def port_post_data(**kw): port = db_utils.get_test_port(**kw) # These values are not part of the API object port.pop('version') port.pop('node_id') port.pop('portgroup_id') internal = port_controller.PortPatchType.internal_attrs() return remove_internal(port, internal)
def port_post_data(**kw): port = utils.get_test_port(**kw) # node_id is not part of the API object port.pop('node_id') # portgroup_id is not part of the API object port.pop('portgroup_id') internal = port_controller.PortPatchType.internal_attrs() return remove_internal(port, internal)
def port_post_data(**kw): port = db_utils.get_test_port(**kw) # These values are not part of the API object port.pop('version') port.pop('node_id') port.pop('portgroup_id') # NOTE(mgoddard): Physical network is not yet supported by the REST API. port.pop('physical_network') internal = port_controller.PortPatchType.internal_attrs() return remove_internal(port, internal)
def test_create(self): port = objects.Port(self.context, **self.fake_port) with mock.patch.object(self.dbapi, 'create_port', autospec=True) as mock_create_port: mock_create_port.return_value = db_utils.get_test_port() port.create() args, _kwargs = mock_create_port.call_args self.assertEqual(objects.Port.VERSION, args[0]['version'])
def port_post_data(**kw): port = utils.get_test_port(**kw) # node_id is not part of the API object port.pop('node_id') # TODO(vsaienko): remove when API part is added port.pop('local_link_connection') port.pop('pxe_enabled') # portgroup_id is not part of the API object port.pop('portgroup_id') internal = port_controller.PortPatchType.internal_attrs() return remove_internal(port, internal)
def test_refresh(self): uuid = self.fake_port["uuid"] returns = [self.fake_port, utils.get_test_port(address="c3:54:00:cf:2d:40")] expected = [mock.call(uuid), mock.call(uuid)] with mock.patch.object(self.dbapi, "get_port_by_uuid", side_effect=returns, autospec=True) as mock_get_port: p = objects.Port.get_by_uuid(self.context, uuid) self.assertEqual("52:54:00:cf:2d:31", p.address) p.refresh() self.assertEqual("c3:54:00:cf:2d:40", p.address) self.assertEqual(expected, mock_get_port.call_args_list) self.assertEqual(self.context, p._context)
def get_test_port(ctxt, **kw): """Return a Port object with appropriate attributes. NOTE: The object leaves the attributes marked as changed, such that a create() could be used to commit it to the DB. """ db_port = db_utils.get_test_port(**kw) # Let DB generate ID if it isn't specified explicitly if 'id' not in kw: del db_port['id'] port = objects.Port(ctxt) for key in db_port: setattr(port, key, db_port[key]) return port
def test_save(self): uuid = self.fake_port["uuid"] address = "b2:54:00:cf:2d:40" test_time = datetime.datetime(2000, 1, 1, 0, 0) with mock.patch.object(self.dbapi, "get_port_by_uuid", autospec=True) as mock_get_port: mock_get_port.return_value = self.fake_port with mock.patch.object(self.dbapi, "update_port", autospec=True) as mock_update_port: mock_update_port.return_value = utils.get_test_port(address=address, updated_at=test_time) p = objects.Port.get_by_uuid(self.context, uuid) p.address = address p.save() mock_get_port.assert_called_once_with(uuid) mock_update_port.assert_called_once_with(uuid, {"address": "b2:54:00:cf:2d:40"}) self.assertEqual(self.context, p._context) res_updated_at = (p.updated_at).replace(tzinfo=None) self.assertEqual(test_time, res_updated_at)
def test_refresh(self): uuid = self.fake_port['uuid'] returns = [ self.fake_port, utils.get_test_port(address="c3:54:00:cf:2d:40") ] expected = [mock.call(uuid), mock.call(uuid)] with mock.patch.object(self.dbapi, 'get_port_by_uuid', side_effect=returns, autospec=True) as mock_get_port: p = objects.Port.get_by_uuid(self.context, uuid) self.assertEqual("52:54:00:cf:2d:31", p.address) p.refresh() self.assertEqual("c3:54:00:cf:2d:40", p.address) self.assertEqual(expected, mock_get_port.call_args_list) self.assertEqual(self.context, p._context)
def test_save(self): uuid = self.fake_port['uuid'] address = "b2:54:00:cf:2d:40" test_time = datetime.datetime(2000, 1, 1, 0, 0) with mock.patch.object(self.dbapi, 'get_port_by_uuid', autospec=True) as mock_get_port: mock_get_port.return_value = self.fake_port with mock.patch.object(self.dbapi, 'update_port', autospec=True) as mock_update_port: mock_update_port.return_value = (utils.get_test_port( address=address, updated_at=test_time)) p = objects.Port.get_by_uuid(self.context, uuid) p.address = address p.save() mock_get_port.assert_called_once_with(uuid) mock_update_port.assert_called_once_with( uuid, {'address': "b2:54:00:cf:2d:40"}) self.assertEqual(self.context, p._context) res_updated_at = (p.updated_at).replace(tzinfo=None) self.assertEqual(test_time, res_updated_at)
def test_create_port(self): fake_port = db_utils.get_test_port() self._test_rpcapi('create_port', 'call', version='1.41', port_obj=fake_port)
def setUp(self): super(TestConvertToVersion, self).setUp() self.vif_id = 'some_uuid' extra = {'vif_port_id': self.vif_id} self.fake_port = db_utils.get_test_port(extra=extra)
def port_post_data(**kw): port = utils.get_test_port(**kw) # node_id is not part of the API object port.pop('node_id') internal = port_controller.PortPatchType.internal_attrs() return remove_internal(port, internal)
def test_update_port(self): fake_port = dbutils.get_test_port() self._test_rpcapi("update_port", "call", version="1.13", port_obj=fake_port)
def setUp(self): super(TestConvertToVersion, self).setUp() self.fake_port = db_utils.get_test_port()
def setUp(self): super(TestPortObject, self).setUp() self.fake_port = db_utils.get_test_port(name='port-name')
def test_update_port(self): fake_port = dbutils.get_test_port() self._test_rpcapi('update_port', 'call', version='1.13', port_obj=fake_port)
def setUp(self): super(TestPortObject, self).setUp() self.fake_port = utils.get_test_port()
def port_post_data(**kw): port = db_utils.get_test_port(**kw) return remove_other_fields(port, port_controller.PORT_SCHEMA['properties'])