def test_save(self):
        uuid = self.fake_portgroup['uuid']
        address = "b2:54:00:cf:2d:40"
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi,
                               'get_portgroup_by_uuid',
                               autospec=True) as mock_get_portgroup:
            mock_get_portgroup.return_value = self.fake_portgroup
            with mock.patch.object(self.dbapi,
                                   'update_portgroup',
                                   autospec=True) as mock_update_portgroup:
                mock_update_portgroup.return_value = (
                    db_utils.get_test_portgroup(address=address,
                                                updated_at=test_time))
                p = objects.Portgroup.get_by_uuid(self.context, uuid)
                p.address = address
                p.save()

                mock_get_portgroup.assert_called_once_with(uuid)
                mock_update_portgroup.assert_called_once_with(
                    uuid, {
                        'version': objects.Portgroup.VERSION,
                        '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(self):
        portgroup = objects.Portgroup(self.context, **self.fake_portgroup)
        with mock.patch.object(self.dbapi, 'create_portgroup',
                               autospec=True) as mock_create_portgroup:
            mock_create_portgroup.return_value = db_utils.get_test_portgroup()

            portgroup.create()

            args, _kwargs = mock_create_portgroup.call_args
            self.assertEqual(objects.Portgroup.VERSION, args[0]['version'])
Exemplo n.º 3
0
def get_test_portgroup(ctxt, **kw):
    """Return a Portgroup 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_portgroup = db_utils.get_test_portgroup(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_portgroup['id']
    portgroup = objects.Portgroup(ctxt)
    for key in db_portgroup:
        setattr(portgroup, key, db_portgroup[key])
    return portgroup
    def test_refresh(self):
        uuid = self.fake_portgroup['uuid']
        returns = [self.fake_portgroup,
                   db_utils.get_test_portgroup(address="c3:54:00:cf:2d:40")]
        expected = [mock.call(uuid), mock.call(uuid)]
        with mock.patch.object(self.dbapi, 'get_portgroup_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_portgroup:
            p = objects.Portgroup.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_portgroup.call_args_list)
            self.assertEqual(self.context, p._context)
Exemplo n.º 5
0
def portgroup_post_data(**kw):
    """Return a Portgroup object without internal attributes."""
    portgroup = utils.get_test_portgroup(**kw)

    # node_id is not a part of the API object
    portgroup.pop('node_id')

    # NOTE(jroll): pop out fields that were introduced in later API versions,
    # unless explicitly requested. Otherwise, these will cause tests using
    # older API versions to fail.
    new_api_ver_arguments = ['mode', 'properties']
    for arg in new_api_ver_arguments:
        if arg not in kw:
            portgroup.pop(arg)

    internal = portgroup_controller.PortgroupPatchType.internal_attrs()
    return remove_internal(portgroup, internal)
Exemplo n.º 6
0
def portgroup_post_data(**kw):
    """Return a Portgroup object without internal attributes."""
    portgroup = db_utils.get_test_portgroup(**kw)

    # These values are not part of the API object
    portgroup.pop('version')
    portgroup.pop('node_id')

    # NOTE(jroll): pop out fields that were introduced in later API versions,
    # unless explicitly requested. Otherwise, these will cause tests using
    # older API versions to fail.
    new_api_ver_arguments = ['mode', 'properties']
    for arg in new_api_ver_arguments:
        if arg not in kw:
            portgroup.pop(arg)

    return remove_other_fields(
        portgroup, portgroup_controller.PORTGROUP_SCHEMA['properties'])
Exemplo n.º 7
0
def portgroup_post_data(**kw):
    """Return a Portgroup object without internal attributes."""
    portgroup = db_utils.get_test_portgroup(**kw)

    # These values are not part of the API object
    portgroup.pop('version')
    portgroup.pop('node_id')

    # NOTE(jroll): pop out fields that were introduced in later API versions,
    # unless explicitly requested. Otherwise, these will cause tests using
    # older API versions to fail.
    new_api_ver_arguments = ['mode', 'properties']
    for arg in new_api_ver_arguments:
        if arg not in kw:
            portgroup.pop(arg)

    internal = portgroup_controller.PortgroupPatchType.internal_attrs()
    return remove_internal(portgroup, internal)
Exemplo n.º 8
0
    def test_save(self):
        uuid = self.fake_portgroup['uuid']
        address = "b2:54:00:cf:2d:40"
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_portgroup_by_uuid',
                               autospec=True) as mock_get_portgroup:
            mock_get_portgroup.return_value = self.fake_portgroup
            with mock.patch.object(self.dbapi, 'update_portgroup',
                                   autospec=True) as mock_update_portgroup:
                mock_update_portgroup.return_value = (
                    utils.get_test_portgroup(address=address,
                                             updated_at=test_time))
                p = objects.Portgroup.get_by_uuid(self.context, uuid)
                p.address = address
                p.save()

                mock_get_portgroup.assert_called_once_with(uuid)
                mock_update_portgroup.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)
Exemplo n.º 9
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_node = db_utils.get_test_node(driver='fake-driver')
     self.fake_node_obj = objects.Node._from_db_object(
         self.context, objects.Node(), self.fake_node)
     self.fake_portgroup = db_utils.get_test_portgroup()
 def setUp(self):
     super(TestPortgroupObject, self).setUp()
     self.fake_portgroup = db_utils.get_test_portgroup()
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.vif_id = 'some_uuid'
     extra = {'vif_port_id': self.vif_id}
     self.fake_portgroup = db_utils.get_test_portgroup(extra=extra)
Exemplo n.º 12
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_node = dbutils.get_test_node(driver='fake-driver')
     self.fake_node_obj = objects.Node._from_db_object(
         objects.Node(self.context), self.fake_node)
     self.fake_portgroup = dbutils.get_test_portgroup()
Exemplo n.º 13
0
def portgroup_post_data(**kw):
    """Return a Portgroup object without internal attributes."""
    portgroup = utils.get_test_portgroup(**kw)
    portgroup.pop('node_id')
    internal = portgroup_controller.PortgroupPatchType.internal_attrs()
    return remove_internal(portgroup, internal)
Exemplo n.º 14
0
def portgroup_post_data(**kw):
    """Return a Portgroup object without internal attributes."""
    portgroup = utils.get_test_portgroup(**kw)
    portgroup.pop('node_id')
    internal = portgroup_controller.PortgroupPatchType.internal_attrs()
    return remove_internal(portgroup, internal)