def test_create_firewall_rule(self): network = Network(self.config['config'], self.ctx.logger, self.config['network']) networks = network.list() item = utils.get_item_from_gcp_response( 'name', self.config['network']['name'], networks) self.assertIsNone(item) firewall = FirewallRule(self.config['config'], self.ctx.logger, self.config['firewall'], self.config['config']['network']) firewall_rules = firewall.list() item = utils.get_item_from_gcp_response('name', firewall.name, firewall_rules) self.assertIsNone(item) network.create() networks = network.list() item = utils.get_item_from_gcp_response( 'name', self.config['network']['name'], networks) self.assertIsNotNone(item) firewall.create() firewall_rules = firewall.list() item = utils.get_item_from_gcp_response( 'name', firewall.name, firewall_rules) self.assertIsNotNone(item) firewall.delete() firewall_rules = firewall.list() item = utils.get_item_from_gcp_response( 'name', firewall.name, firewall_rules) self.assertIsNone(item) network.delete() networks = network.list() item = utils.get_item_from_gcp_response( 'name', self.config['network']['name'], networks) self.assertIsNone(item)
def test_tag_firewall(self): network = Network(self.config['config'], self.ctx.logger, self.config['network']) network.create() firewall_rule = dict(self.config['firewall']) source_tag = 'source-tag' target_tag = 'target-tag' firewall_rule['sourceTags'] = [source_tag] firewall_rule['targetTags'] = [target_tag] firewall = FirewallRule(self.config['config'], self.ctx.logger, firewall_rule, self.config['config']['network']) firewall.create() firewall_name = firewall.name firewalls = firewall.list() item = utils.get_item_from_gcp_response('name', firewall_name, firewalls) self.assertEqual(source_tag, find_in_list(source_tag, item['sourceTags'])) self.assertEqual(target_tag, find_in_list(target_tag, item['targetTags'])) firewall.firewall = self.config['firewall'] firewall.firewall['name'] = firewall_name firewall.update() firewalls = firewall.list() item = utils.get_item_from_gcp_response('name', firewall_rule['name'], firewalls) self.assertIsNone(find_in_list(source_tag, item.get('sourceTags', []))) self.assertIsNone(find_in_list(target_tag, item.get('targetTags', []))) firewall.firewall = firewall_rule firewall.firewall['name'] = firewall_name firewall.update() firewalls = firewall.list() item = utils.get_item_from_gcp_response('name', firewall_rule['name'], firewalls) self.assertEqual(source_tag, find_in_list(source_tag, item['sourceTags'])) self.assertEqual(target_tag, find_in_list(target_tag, item['targetTags'])) firewall.delete() network.delete()
def test_create_firewall_rule(self): network = Network(self.config['config'], self.ctx.logger, self.config['network']) networks = network.list() item = utils.get_item_from_gcp_response('name', self.config['network']['name'], networks) self.assertIsNone(item) firewall = FirewallRule(self.config['config'], self.ctx.logger, self.config['firewall'], self.config['config']['network']) firewall_rules = firewall.list() item = utils.get_item_from_gcp_response('name', firewall.name, firewall_rules) self.assertIsNone(item) network.create() networks = network.list() item = utils.get_item_from_gcp_response('name', self.config['network']['name'], networks) self.assertIsNotNone(item) firewall.create() firewall_rules = firewall.list() item = utils.get_item_from_gcp_response('name', firewall.name, firewall_rules) self.assertIsNotNone(item) firewall.delete() firewall_rules = firewall.list() item = utils.get_item_from_gcp_response('name', firewall.name, firewall_rules) self.assertIsNone(item) network.delete() networks = network.list() item = utils.get_item_from_gcp_response('name', self.config['network']['name'], networks) self.assertIsNone(item)