def test_set_common_metadata_ssh_keys(self): # save current project metadata before_test_state = self._get_project() before_test_metadata = before_test_state['commonInstanceMetadata'] before_test_metadata.pop('kind', None) before_test_metadata.pop('fingerprint', None) self._add_cleanup(self._set_common_metadata, before_test_metadata) # do test metadata = {'items': [{'key': 'sshKeys', 'value': SSH_KEY}]} self._set_common_metadata(metadata) project = self._get_project() # make 're template' from ssh key because assertObject use re.match metadata['items'][0]['value'] = test_base.string_to_re_pattern(SSH_KEY) expected_project = { 'name': self.cfg.project_id, 'commonInstanceMetadata': metadata } expected_project = self._get_expected_project(expected_project) self.assertObject(expected_project, project) # return previous state self._set_common_metadata(before_test_metadata) self._remove_cleanup(self._set_common_metadata, before_test_metadata) project = self._get_project() # make 're template' from ssh key because assertObject use re.match for i in before_test_metadata.get('items', []): if i['key'] == 'sshKeys': i['value'] = test_base.string_to_re_pattern(i['value']) # check object self.assertObject(before_test_state, project)
def test_set_common_metadata_ssh_keys(self): # save current project metadata before_test_state = self._get_project() before_test_metadata = before_test_state['commonInstanceMetadata'] before_test_metadata.pop('kind', None) before_test_metadata.pop('fingerprint', None) self._add_cleanup(self._set_common_metadata, before_test_metadata) # do test metadata = { 'items': [ { 'key': 'sshKeys', 'value': SSH_KEY } ] } self._set_common_metadata(metadata) project = self._get_project() # make 're template' from ssh key because assertObject use re.match metadata['items'][0]['value'] = test_base.string_to_re_pattern(SSH_KEY) expected_project = { 'name': self.cfg.project_id, 'commonInstanceMetadata': metadata } expected_project = self._get_expected_project(expected_project) self.assertObject(expected_project, project) # return previous state self._set_common_metadata(before_test_metadata) self._remove_cleanup(self._set_common_metadata, before_test_metadata) project = self._get_project() # make 're template' from ssh key because assertObject use re.match for i in before_test_metadata.get('items', []): if i['key'] == 'sshKeys': i['value'] = test_base.string_to_re_pattern(i['value']) # check object self.assertObject(before_test_state, project)
def ip_to_re_pattern(ip): return test_base.string_to_re_pattern(ip)