def test_tag_instance(self): test_tag = 'agent-123' name = 'name' self.config['config']['network'] = 'default' instance = Instance(self.config['config'], self.ctx.logger, name=name, image=self.config['instance']['image'], tags=[test_tag], machine_type=self.config['instance_type']) instance.create() instances = instance.list() item = utils.get_item_from_gcp_response('name', name, instances) tag = find_in_list(test_tag, item['tags'].get('items')) self.assertIsNotNone(tag) instance.delete() instance.tags = [] instance.create() instances = instance.list() item = utils.get_item_from_gcp_response('name', name, instances) tags = item.get('tags', []) tag = find_in_list(test_tag, tags.get('items', [])) self.assertIsNone(tag) instance.set_tags([test_tag]) instances = instance.list() item = utils.get_item_from_gcp_response('name', name, instances) tag = find_in_list(test_tag, item['tags'].get('items')) self.assertIsNotNone(tag) instance.delete()
def test_create_instance(self): config = self.inputs['config'] instance = Instance(config, ctx.logger, name=ctx.instance.id) instances = instance.list() base = len(instances.get('items', [])) ctx.logger.info('Install workflow') # execute install workflow self.env.execute('install', task_retries=0) ctx.logger.info('Check instance number') instances = instance.list() self.assertEqual(len(instances['items']), base + 1) ctx.logger.info('Uninstall workflow') self.env.execute('uninstall', task_retries=0) ctx.logger.info('Check instance number') instances = instance.list() self.assertEqual(len(instances.get('items', [])), base)