def test_delete_hosting_device_resources(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) mgmt_context = {'mgmt_nw_id': None} plugging_driver = HwVLANTrunkingPlugDriver() res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 2) nets = self._list('networks') self.assertEqual(len(nets['networks']), 0) subnets = self._list('subnets') self.assertEqual(len(subnets['subnets']), 0) ports = self._list('ports') self.assertEqual(len(ports['ports']), 0) # avoid passing the mgmt port twice in argument list mgmt_port = res['mgmt_port'] del res['mgmt_port'] plugging_driver.delete_hosting_device_resources( ctx, tenant_id, mgmt_port, **res) nets = self._list('networks')['networks'] # no networks and subnets should remain self.assertEqual(len(nets), 0) subnets = self._list('subnets')['subnets'] self.assertEqual(len(subnets), 0) ports = self._list('ports') self.assertEqual(len(ports['ports']), 0)
def test_create_hosting_device_resources_no_mgmt_context(self): tenant_id = "some_tenant_id" ctx = context.Context("", tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() res = plugging_driver.create_hosting_device_resources(ctx, "some_id", tenant_id, None, 2) self.assertIsNone(res["mgmt_port"], res) self.assertEqual(len(res), 1)
def test_delete_hosting_device_resources(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) mgmt_context = {'mgmt_nw_id': None} plugging_driver = HwVLANTrunkingPlugDriver() res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 2) nets = self._list('networks') self.assertEqual(len(nets['networks']), 0) subnets = self._list('subnets') self.assertEqual(len(subnets['subnets']), 0) ports = self._list('ports') self.assertEqual(len(ports['ports']), 0) # avoid passing the mgmt port twice in argument list mgmt_port = res['mgmt_port'] del res['mgmt_port'] plugging_driver.delete_hosting_device_resources( ctx, tenant_id, mgmt_port, **res) nets = self._list('networks')['networks'] # no networks and subnets should remain self.assertEqual(len(nets), 0) subnets = self._list('subnets')['subnets'] self.assertEqual(len(subnets), 0) ports = self._list('ports') self.assertEqual(len(ports['ports']), 0)
def test_create_hosting_device_resources_no_mgmt_context(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, None, 2) self.assertIsNone(res['mgmt_port'], res) self.assertEqual(len(res), 1)
def test_create_hosting_device_resources(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {'mgmt_nw_id': None} res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 2) self.assertIsNone(res['mgmt_port']) self.assertEqual(len(res), 1)
def test_get_hosting_device_resources_by_complementary_id(self): tenant_id = "some_tenant_id" ctx = context.Context("", tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {"mgmt_nw_id": None} res = plugging_driver.create_hosting_device_resources(ctx, "some_id", tenant_id, mgmt_context, 1) # ports that should not be returned with self.port(), self.port(device_id="uuid2"), self.port(tenant_id=tenant_id): res_get = plugging_driver.get_hosting_device_resources(ctx, "", "some_id", tenant_id, None) self.assertIsNone(res_get["mgmt_port"]) self.assertEqual(len(res), 1)
def test_get_hosting_device_resources_by_complementary_id(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {'mgmt_nw_id': None} res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 1) # ports that should not be returned with self.port(), self.port(device_id='uuid2'), self.port( tenant_id=tenant_id): res_get = plugging_driver.get_hosting_device_resources( ctx, '', 'some_id', tenant_id, None) self.assertIsNone(res_get['mgmt_port']) self.assertEqual(len(res), 1)
def test_get_hosting_device_resources_by_device_id(self): tenant_id = "some_tenant_id" ctx = context.Context("", tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {"mgmt_nw_id": None} res = plugging_driver.create_hosting_device_resources(ctx, "some_id", tenant_id, mgmt_context, 1) # update attributes of created ports to fake what Nova updates hd_uuid = "hd_uuid1" update_spec = {"port": {"device_id": hd_uuid, "device_owner": "nova"}} for hd_port in self._list("ports")["ports"]: self._update("ports", hd_port["id"], update_spec) # ports that should not be returned with self.port(), self.port(device_id="uuid2"), self.port(tenant_id=tenant_id), self.port( tenant_id=tenant_id, device_owner="other_uuid" ): res_get = plugging_driver.get_hosting_device_resources(ctx, hd_uuid, "some_id", tenant_id, None) self.assertIsNone(res_get["mgmt_port"]) self.assertEqual(len(res), 1)
def test_get_hosting_device_resources_by_device_id(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {'mgmt_nw_id': None} res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 1) # update attributes of created ports to fake what Nova updates hd_uuid = 'hd_uuid1' update_spec = {'port': {'device_id': hd_uuid, 'device_owner': 'nova'}} for hd_port in self._list('ports')['ports']: self._update('ports', hd_port['id'], update_spec) # ports that should not be returned with self.port(), self.port(device_id='uuid2'), self.port( tenant_id=tenant_id), self.port(tenant_id=tenant_id, device_owner='other_uuid'): res_get = plugging_driver.get_hosting_device_resources( ctx, hd_uuid, 'some_id', tenant_id, None) self.assertIsNone(res_get['mgmt_port']) self.assertEqual(len(res), 1)
def test_get_hosting_device_resources_by_device_id(self): tenant_id = 'some_tenant_id' ctx = context.Context('', tenant_id, is_admin=True) plugging_driver = HwVLANTrunkingPlugDriver() mgmt_context = {'mgmt_nw_id': None} res = plugging_driver.create_hosting_device_resources( ctx, "some_id", tenant_id, mgmt_context, 1) # update attributes of created ports to fake what Nova updates hd_uuid = 'hd_uuid1' update_spec = {'port': {'device_id': hd_uuid, 'device_owner': 'nova'}} for hd_port in self._list('ports')['ports']: self._update('ports', hd_port['id'], update_spec) # ports that should not be returned with self.port(), self.port(device_id='uuid2'), self.port( tenant_id=tenant_id), self.port(tenant_id=tenant_id, device_owner='other_uuid'): res_get = plugging_driver.get_hosting_device_resources( ctx, hd_uuid, 'some_id', tenant_id, None) self.assertIsNone(res_get['mgmt_port']) self.assertEqual(len(res), 1)
def test_delete_hosting_device_resources(self): tenant_id = "some_tenant_id" ctx = context.Context("", tenant_id, is_admin=True) mgmt_context = {"mgmt_nw_id": None} plugging_driver = HwVLANTrunkingPlugDriver() res = plugging_driver.create_hosting_device_resources(ctx, "some_id", tenant_id, mgmt_context, 2) nets = self._list("networks") self.assertEqual(len(nets["networks"]), 0) subnets = self._list("subnets") self.assertEqual(len(subnets["subnets"]), 0) ports = self._list("ports") self.assertEqual(len(ports["ports"]), 0) # avoid passing the mgmt port twice in argument list mgmt_port = res["mgmt_port"] del res["mgmt_port"] plugging_driver.delete_hosting_device_resources(ctx, tenant_id, mgmt_port, **res) nets = self._list("networks")["networks"] # no networks and subnets should remain self.assertEqual(len(nets), 0) subnets = self._list("subnets")["subnets"] self.assertEqual(len(subnets), 0) ports = self._list("ports") self.assertEqual(len(ports["ports"]), 0)