def test_list(self): block1 = factory.create_block(self.tenant_id) block2 = factory.create_block(self.tenant_id) list_res = functional.run("ip_block list -t %s" % self.tenant_id) self.assertEqual(0, list_res['exitcode']) self.assertEqual(sorted([block1, block2]), sorted(factory.model('ip_blocks', list_res)))
def test_crud(self): block = factory.create_block(cidr="77.1.1.0/24", tenant_id=self.tenant_id) create_res = self.command("ip_route create", ip_block_id=block['id'], destination="10.1.1.2", gateway="10.1.1.1", netmask="255.255.255.0") route = factory.model("ip_route", create_res) self.assertShows("ip_route", route, parameters="ip_block_id=%s id=%s" % (block['id'], route['id'])) another_create_res = self.command("ip_route create", ip_block_id=block['id'], destination="20.1.1.2", gateway="20.1.1.1", netmask="255.255.255.0") another_route = factory.model("ip_route", another_create_res) list_res = self.command("ip_route list", ip_block_id=block['id']) self.assertTableEquals([route, another_route], list_res['out']) self.command("ip_route delete", ip_block_id=block['id'], id=route['id']) self.assertResourceNotFound("ip_route", route, parameters="ip_block_id=%s id=%s" % (block['id'], route['id']))
def test_list_with_tenant(self): device1_id, device2_id = uuid.uuid4(), uuid.uuid4() tenant1_id, tenant2_id = uuid.uuid4(), uuid.uuid4() block = factory.create_block(cidr="30.1.1.1/24", tenant_id=self.tenant_id) tenant1_ip1 = factory.create_ip(block_id=block['id'], address="30.1.1.2", used_by_device=device1_id, tenant_id=self.tenant_id, used_by_tenant=tenant1_id,) tenant1_ip2 = factory.create_ip(block_id=block['id'], address="30.1.1.3", used_by_device=device1_id, tenant_id=self.tenant_id, used_by_tenant=tenant1_id,) tenant2_ip1 = factory.create_ip(block_id=block['id'], address="30.1.1.4", used_by_device=device2_id, tenant_id=self.tenant_id, used_by_tenant=tenant2_id) list_res = functional.run("allocated_ip list -t %s" % tenant1_id) self.assertEqual(sorted([tenant1_ip1, tenant1_ip2]), sorted(yaml.load(list_res['out'])['ip_addresses']))
def test_crud(self): network_id = uuid.uuid4() block = factory.create_block(cidr="20.1.1.0/24", network_id=network_id, tenant_id=self.tenant_id) iface = factory.create_interface(network_id=network_id, tenant_id=self.tenant_id) ip = factory.create_ip(address="20.1.1.2", block_id=block['id'], used_by_tenant=self.tenant_id, tenant_id=self.tenant_id) another_ip = factory.create_ip(address="20.1.1.3", block_id=block['id'], used_by_tenant=self.tenant_id, tenant_id=self.tenant_id) ip_res = self.command("allowed_ip create", interface_id=iface['id'], network_id=network_id, ip_address=ip['address']) allowed_ip = factory.model("ip_address", ip_res) self.assertShows("ip_address", allowed_ip, parameters="interface_id=%s ip_address=%s" % (iface['id'], ip['address']), command_name="allowed_ip") another_ip_res = self.command("allowed_ip create", interface_id=iface['id'], network_id=network_id, ip_address=another_ip['address']) another_allowed_ip = factory.model('ip_address', another_ip_res) list_res = self.command("allowed_ip list", interface_id=iface['id']) actual_allowed_ips = yaml.load(list_res['out'])['ip_addresses'] self.assertTrue(allowed_ip in actual_allowed_ips) self.assertTrue(another_allowed_ip in actual_allowed_ips) self.command("allowed_ip delete", interface_id=iface['id'], ip_address=ip['address']) show_res = self.command("allowed_ip show", interface_id=iface['id'], ip_address=ip['address'], raise_error=False) expected_error = ("Ip Address %s hasnt been allowed on interface %s" % (ip['address'], iface['id'])) self.assertTrue(expected_error in show_res['out'])
def test_crud(self): network_id = uuid.uuid4() block = factory.create_block(cidr="20.1.1.0/24", network_id=network_id, tenant_id=self.tenant_id) iface = factory.create_interface(network_id=network_id, tenant_id=self.tenant_id) self.assertShows("interface", iface, parameters="vif_id=%s" % iface['id']) self.command("interface delete", is_tenanted=False, vif_id=iface['id']) self.assertResourceNotFound("interface", iface, parameters="vif_id=%s" % iface['id'])
def test_create_and_list(self): block = factory.create_block(cidr="10.0.0.0/8", tenant_id="123") subnet_res_1 = functional.run("subnet create parent_id={0} " "cidr=10.0.1.0/29 -t 123".format(block['id'])) self.assertEqual(0, subnet_res_1['exitcode']) subnet_res_2 = functional.run("subnet create parent_id={0} " "cidr=10.0.0.0/29 -t 123".format(block['id'])) self.assertEqual(0, subnet_res_2['exitcode']) subnet_list_res = functional.run("subnet list parent_id={0} " "-t 123".format(block['id'])) self.assertEqual(sorted([factory.model('subnet', subnet_res_1), factory.model('subnet', subnet_res_2)]), sorted(factory.model('subnets', subnet_list_res)))
def test_tenant_id_ignored_when_present(self): network_id = uuid.uuid4() block = factory.create_block(cidr="20.1.1.0/24", network_id=network_id, tenant_id=self.tenant_id) create_res = self.command("interface create", is_tenanted=True, network_id=network_id, vif_id=uuid.uuid4(), tenant_id=self.tenant_id) iface = factory.model('interface', create_res) self.assertShows("interface", iface, command_name="tenant_interface", parameters="vif_id=%s" % iface['id'])
def test_list(self): device1_id, device2_id = uuid.uuid4(), uuid.uuid4() block = factory.create_block(cidr="30.1.1.1/24", tenant_id=self.tenant_id) ip1 = factory.create_ip(block_id=block['id'], address="30.1.1.2", used_by_device=device1_id, tenant_id=self.tenant_id) ip2 = factory.create_ip(block_id=block['id'], address="30.1.1.3", used_by_device=device2_id, tenant_id=self.tenant_id) list_res = self.command("allocated_ip list", is_tenanted=False, used_by_device=device1_id) self.assertEqual([ip1], yaml.load(list_res['out'])['ip_addresses'])
def test_crud(self): block = factory.create_block(cidr="10.1.1.0/24", tenant_id=self.tenant_id) ip = factory.create_ip(block_id=block['id'], address="10.1.1.2", tenant_id=self.tenant_id) self._assert_ip_shows(ip) another_ip = factory.create_ip(block_id=block['id'], address="10.1.1.3", tenant_id=self.tenant_id) list_res = self.command("ip_address list", ip_block_id=block['id']) self.assertEqual(sorted([ip, another_ip]), sorted(yaml.load(list_res['out'])['ip_addresses'])) self.command("ip_address delete", ip_block_id=block['id'], address="10.1.1.2")