@@ -85,6 +85,28 @@ def set_registry(self):
8585 # lower case all registry options for consistency
8686 self .registry = {key .lower (): value for key , value in self .registry .copy ().items ()}
8787
88+ def set_tags (self , previous_config ):
89+ """verify the tags exist on any nodes as labels"""
90+ if not self .tags :
91+ return
92+
93+ # Get all nodes with label selectors
94+ nodes = self ._scheduler ._get_nodes (labels = self .tags ).json ()
95+ if nodes ['items' ]:
96+ return
97+
98+ labels = ['{}={}' .format (key , value ) for key , value in self .tags .items ()]
99+ message = 'No nodes matched the provided labels: {}' .format (', ' .join (labels ))
100+
101+ # Find out if there are any other tags around
102+ old_tags = getattr (previous_config , 'tags' )
103+ if old_tags :
104+ old = ['{}={}' .format (key , value ) for key , value in old_tags .items ()]
105+ new = set (labels ) - set (old )
106+ message += ' - Addition of {} is the cause' .format (', ' .join (new ))
107+
108+ raise EnvironmentError (message )
109+
88110 def save (self , ** kwargs ):
89111 """merge the old config with the new"""
90112 try :
@@ -106,27 +128,11 @@ def save(self, **kwargs):
106128 # remove config keys if we provided a null value
107129 [data .pop (k ) for k , v in new_data .items () if v is None ]
108130 setattr (self , attr , data )
131+
132+ self .set_healthchecks ()
133+ self .set_registry ()
134+ self .set_tags (previous_config )
109135 except Config .DoesNotExist :
110136 pass
111137
112- self .set_healthchecks ()
113- self .set_registry ()
114-
115- # verify the tags exist on any nodes as labels
116- if self .tags :
117- # Get all nodes with label selectors
118- nodes = self ._scheduler ._get_nodes (labels = self .tags ).json ()
119- if not nodes ['items' ]:
120- labels = ['{}={}' .format (key , value ) for key , value in self .tags .items ()]
121- message = 'No nodes matched the provided labels: {}' .format (', ' .join (labels ))
122-
123- # Find out if there are any other tags around
124- old_tags = getattr (previous_config , 'tags' )
125- if old_tags :
126- old = ['{}={}' .format (key , value ) for key , value in old_tags .items ()]
127- new = set (labels ) - set (old )
128- message += ' - Addition of {} is the cause' .format (', ' .join (new ))
129-
130- raise EnvironmentError (message )
131-
132138 return super (Config , self ).save (** kwargs )
0 commit comments