示例#1
0
    def test_get_nodeinfo_list_provision(self, mock_utcnow):
        past = datetime.datetime(2000, 1, 1, 0, 0)
        next = past + datetime.timedelta(minutes=8)
        present = past + datetime.timedelta(minutes=10)
        mock_utcnow.return_value = past

        # node with provision_updated timeout
        n1 = utils.get_test_node(id=1, uuid=ironic_utils.generate_uuid(),
                                 provision_updated_at=past)
        # node with None in provision_updated_at
        n2 = utils.get_test_node(id=2, uuid=ironic_utils.generate_uuid(),
                                 provision_state=states.DEPLOYWAIT)
        # node without timeout
        n3 = utils.get_test_node(id=3, uuid=ironic_utils.generate_uuid(),
                                 provision_updated_at=next)
        self.dbapi.create_node(n1)
        self.dbapi.create_node(n2)
        self.dbapi.create_node(n3)

        mock_utcnow.return_value = present
        res = self.dbapi.get_nodeinfo_list(filters={'provisioned_before': 300})
        self.assertEqual([1], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'provision_state':
                                                    states.DEPLOYWAIT})
        self.assertEqual([2], [r[0] for r in res])
示例#2
0
    def test_get_nodeinfo_list_with_filters(self):
        n1 = utils.get_test_node(id=1, driver='driver-one',
                                 instance_uuid=ironic_utils.generate_uuid(),
                                 reservation='fake-host',
                                 uuid=ironic_utils.generate_uuid())
        n2 = utils.get_test_node(id=2, driver='driver-two',
                                 uuid=ironic_utils.generate_uuid(),
                                 maintenance=True)
        self.dbapi.create_node(n1)
        self.dbapi.create_node(n2)

        res = self.dbapi.get_nodeinfo_list(filters={'driver': 'driver-one'})
        self.assertEqual([1], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'driver': 'bad-driver'})
        self.assertEqual([], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'associated': True})
        self.assertEqual([1], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'associated': False})
        self.assertEqual([2], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'reserved': True})
        self.assertEqual([1], [r[0] for r in res])

        res = self.dbapi.get_nodeinfo_list(filters={'reserved': False})
        self.assertEqual([2], [r[0] for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': True})
        self.assertEqual([2], [r.id for r in res])

        res = self.dbapi.get_node_list(filters={'maintenance': False})
        self.assertEqual([1], [r.id for r in res])
示例#3
0
 def test_update_node_name_duplicate(self):
     node1 = utils.create_test_node(uuid=ironic_utils.generate_uuid(),
                                    name='spam')
     node2 = utils.create_test_node(uuid=ironic_utils.generate_uuid())
     self.assertRaises(exception.DuplicateName,
                       self.dbapi.update_node,
                       node2.id,
                       {'name': node1.name})
示例#4
0
 def test_create_node_instance_already_associated(self):
     instance = ironic_utils.generate_uuid()
     utils.create_test_node(uuid=ironic_utils.generate_uuid(),
                            instance_uuid=instance)
     self.assertRaises(exception.InstanceAssociated,
                       utils.create_test_node,
                       uuid=ironic_utils.generate_uuid(),
                       instance_uuid=instance)
示例#5
0
    def test_node_by_instance_uuid_wrong_uuid(self):
        obj_utils.create_test_node(self.context, uuid=utils.generate_uuid(),
                                   instance_uuid=utils.generate_uuid())
        wrong_uuid = utils.generate_uuid()

        data = self.get_json('/nodes?instance_uuid=%s' % wrong_uuid)

        self.assertThat(data['nodes'], HasLength(0))
示例#6
0
 def test_update_node_instance_already_associated(self):
     node1 = utils.create_test_node(uuid=ironic_utils.generate_uuid())
     new_i_uuid = ironic_utils.generate_uuid()
     self.dbapi.update_node(node1.id, {'instance_uuid': new_i_uuid})
     node2 = utils.create_test_node(uuid=ironic_utils.generate_uuid())
     self.assertRaises(exception.InstanceAssociated,
                       self.dbapi.update_node,
                       node2.id,
                       {'instance_uuid': new_i_uuid})
示例#7
0
 def test_update_node_already_assosicated(self):
     n = self._create_test_node()
     new_i_uuid_one = ironic_utils.generate_uuid()
     self.dbapi.update_node(n['id'], {'instance_uuid': new_i_uuid_one})
     new_i_uuid_two = ironic_utils.generate_uuid()
     self.assertRaises(exception.NodeAssociated,
                       self.dbapi.update_node,
                       n['id'],
                       {'instance_uuid': new_i_uuid_two})
示例#8
0
    def test_node_by_instance_uuid_wrong_uuid(self):
        ndict = dbutils.get_test_node(uuid=utils.generate_uuid(),
                                      instance_uuid=utils.generate_uuid())
        self.dbapi.create_node(ndict)
        wrong_uuid = utils.generate_uuid()

        data = self.get_json('/nodes?instance_uuid=%s' % wrong_uuid)

        self.assertThat(data['nodes'], HasLength(0))
示例#9
0
 def test_update_node_instance_already_associated(self):
     n = self._create_test_node(id=1, uuid=ironic_utils.generate_uuid())
     new_i_uuid = ironic_utils.generate_uuid()
     self.dbapi.update_node(n['id'], {'instance_uuid': new_i_uuid})
     n = self._create_test_node(id=2, uuid=ironic_utils.generate_uuid())
     self.assertRaises(exception.InstanceAssociated,
                       self.dbapi.update_node,
                       n['id'],
                       {'instance_uuid': new_i_uuid})
示例#10
0
 def test_create_node_instance_already_associated(self):
     instance = ironic_utils.generate_uuid()
     n1 = utils.get_test_node(id=1, uuid=ironic_utils.generate_uuid(),
                              instance_uuid=instance)
     self.dbapi.create_node(n1)
     n2 = utils.get_test_node(id=2, uuid=ironic_utils.generate_uuid(),
                              instance_uuid=instance)
     self.assertRaises(exception.InstanceAssociated,
                       self.dbapi.create_node, n2)
示例#11
0
 def _check_3bea56f25597(self, engine, data):
     nodes = db_utils.get_table(engine, "nodes")
     instance_uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
     data = {"driver": "fake", "uuid": utils.generate_uuid(), "instance_uuid": instance_uuid}
     nodes.insert().values(data).execute()
     data["uuid"] = utils.generate_uuid()
     # TODO(viktors): Remove check on sqlalchemy.exc.IntegrityError, when
     #                Ironic will use oslo.db 0.4.0 or higher.
     #                See bug #1214341 for details.
     self.assertRaises((sqlalchemy.exc.IntegrityError, exception.DBDuplicateEntry), nodes.insert().execute, data)
示例#12
0
 def _check_3bea56f25597(self, engine, data):
     nodes = db_utils.get_table(engine, 'nodes')
     instance_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
     data = {'driver': 'fake',
             'uuid': utils.generate_uuid(),
             'instance_uuid': instance_uuid}
     nodes.insert().values(data).execute()
     data['uuid'] = utils.generate_uuid()
     self.assertRaises(sqlalchemy.exc.IntegrityError,
                       nodes.insert().execute, data)
示例#13
0
    def test_node_by_instance_uuid(self):
        ndict = dbutils.get_test_node(uuid=utils.generate_uuid(),
                                      instance_uuid=utils.generate_uuid())
        node = self.dbapi.create_node(ndict)
        instance_uuid = node['instance_uuid']

        data = self.get_json('/nodes?instance_uuid=%s' % instance_uuid)

        self.assertThat(data['nodes'], HasLength(1))
        self.assertEqual(node['instance_uuid'],
                         data['nodes'][0]["instance_uuid"])
示例#14
0
    def test_node_by_instance_uuid(self):
        node = obj_utils.create_test_node(self.context,
                                          uuid=utils.generate_uuid(),
                                          instance_uuid=utils.generate_uuid())
        instance_uuid = node.instance_uuid

        data = self.get_json('/nodes?instance_uuid=%s' % instance_uuid)

        self.assertThat(data['nodes'], HasLength(1))
        self.assertEqual(node['instance_uuid'],
                         data['nodes'][0]["instance_uuid"])
示例#15
0
 def test__get_node_vif_ids_two_ports(self):
     port1 = self._create_test_port(node_id=self.node.id, id=6,
                                    address='aa:bb:cc',
                                    uuid=utils.generate_uuid(),
                                    extra={'vif_port_id': 'test-vif-A'})
     port2 = self._create_test_port(node_id=self.node.id, id=7,
                                    address='dd:ee:ff',
                                    uuid=utils.generate_uuid(),
                                    extra={'vif_port_id': 'test-vif-B'})
     expected = {port1.uuid: 'test-vif-A', port2.uuid: 'test-vif-B'}
     with task_manager.acquire(self.context, self.node.uuid) as task:
         result = pxe._get_node_vif_ids(task)
     self.assertEqual(expected, result)
示例#16
0
 def _check_3bea56f25597(self, engine, data):
     nodes = db_utils.get_table(engine, 'nodes')
     instance_uuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'
     data = {'driver': 'fake',
             'uuid': utils.generate_uuid(),
             'instance_uuid': instance_uuid}
     nodes.insert().values(data).execute()
     data['uuid'] = utils.generate_uuid()
     # TODO(viktors): Remove check on sqlalchemy.exc.IntegrityError, when
     #                Ironic will use oslo_db 0.4.0 or higher.
     #                See bug #1214341 for details.
     self.assertRaises(
         (sqlalchemy.exc.IntegrityError, db_exc.DBDuplicateEntry),
         nodes.insert().execute, data)
示例#17
0
    def test__get_nodes_mac_addresses(self):
        self._create_test_port(node_id=self.node.id,
                               address='aa:bb:cc',
                               uuid=utils.generate_uuid(),
                               id=6)
        self._create_test_port(node_id=self.node.id,
                               address='dd:ee:ff',
                               uuid=utils.generate_uuid(),
                               id=7)

        expected = ['aa:bb:cc', 'dd:ee:ff']
        with task_manager.acquire(self.context, self.node.uuid) as task:
            node_macs = pxe._get_node_mac_addresses(task, self.node)
        self.assertEqual(expected, node_macs)
示例#18
0
 def _pre_upgrade_5674c57409b9(self, engine):
     # add some nodes in various states so we can assert that "None"
     # was replaced by "available", and nothing else changed.
     nodes = db_utils.get_table(engine, 'nodes')
     data = [{'uuid': utils.generate_uuid(),
              'provision_state': 'fake state'},
             {'uuid': utils.generate_uuid(),
              'provision_state': 'active'},
             {'uuid': utils.generate_uuid(),
              'provision_state': 'deleting'},
             {'uuid': utils.generate_uuid(),
              'provision_state': None}]
     nodes.insert().values(data).execute()
     return data
示例#19
0
    def test_detail_with_instance_uuid(self):
        ndict = dbutils.get_test_node(uuid=utils.generate_uuid(),
                                      instance_uuid=utils.generate_uuid())
        node = self.dbapi.create_node(ndict)
        instance_uuid = node['instance_uuid']

        data = self.get_json('/nodes/detail?instance_uuid=%s' % instance_uuid)

        self.assertEqual(node['instance_uuid'],
                         data['nodes'][0]["instance_uuid"])
        self.assertIn('driver', data['nodes'][0])
        self.assertIn('driver_info', data['nodes'][0])
        self.assertIn('extra', data['nodes'][0])
        self.assertIn('properties', data['nodes'][0])
        self.assertIn('chassis_id', data['nodes'][0])
示例#20
0
    def test_JSONEncodedDict_default_value(self):
        # Create chassis w/o extra specified.
        ch1_id = ironic_utils.generate_uuid()
        self.dbapi.create_chassis({'uuid': ch1_id})
        # Get chassis manually to test SA types in isolation from UOM.
        ch1 = sa_api.model_query(models.Chassis).filter_by(uuid=ch1_id).one()
        self.assertEqual({}, ch1.extra)

        # Create chassis with extra specified.
        ch2_id = ironic_utils.generate_uuid()
        extra = {'foo1': 'test', 'foo2': 'other extra'}
        self.dbapi.create_chassis({'uuid': ch2_id, 'extra': extra})
        # Get chassis manually to test SA types in isolation from UOM.
        ch2 = sa_api.model_query(models.Chassis).filter_by(uuid=ch2_id).one()
        self.assertEqual(extra, ch2.extra)
示例#21
0
    def test_remove_multi(self):
        extra = {"foo1": "bar1", "foo2": "bar2", "foo3": "bar3"}
        chassis = obj_utils.create_test_chassis(self.context, extra=extra,
                                                description="foobar",
                                                uuid=utils.generate_uuid(),
                                                id=1)

        # Removing one item from the collection
        response = self.patch_json('/chassis/%s' % chassis.uuid,
                                   [{'path': '/extra/foo2', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
        result = self.get_json('/chassis/%s' % chassis.uuid)
        extra.pop("foo2")
        self.assertEqual(extra, result['extra'])

        # Removing the collection
        response = self.patch_json('/chassis/%s' % chassis.uuid,
                                   [{'path': '/extra', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
        result = self.get_json('/chassis/%s' % chassis.uuid)
        self.assertEqual({}, result['extra'])

        # Assert nothing else was changed
        self.assertEqual(chassis.uuid, result['uuid'])
        self.assertEqual(chassis.description, result['description'])
示例#22
0
 def test_create_port_duplicated_address(self):
     self.dbapi.create_port(self.p)
     dup_address = self.p['address']
     p2 = db_utils.get_test_port(id=123, uuid=ironic_utils.generate_uuid(),
                              node_id=self.n.id, address=dup_address)
     self.assertRaises(exception.MACAlreadyExists,
                       self.dbapi.create_port, p2)
示例#23
0
 def _create_many_test_nodes(self):
     uuids = []
     for i in range(1, 6):
         n = self._create_test_node(id=i, uuid=ironic_utils.generate_uuid())
         uuids.append(n['uuid'])
     uuids.sort()
     return uuids
示例#24
0
文件: api.py 项目: mshabdiz/ironic
 def create_chassis(self, values):
     if not values.get('uuid'):
         values['uuid'] = utils.generate_uuid()
     chassis = models.Chassis()
     chassis.update(values)
     chassis.save()
     return chassis
示例#25
0
 def test_update_node_associate_and_disassociate(self):
     n = self._create_test_node()
     new_i_uuid = ironic_utils.generate_uuid()
     res = self.dbapi.update_node(n['id'], {'instance_uuid': new_i_uuid})
     self.assertEqual(new_i_uuid, res.instance_uuid)
     res = self.dbapi.update_node(n['id'], {'instance_uuid': None})
     self.assertIsNone(res.instance_uuid)
示例#26
0
    def test_node_power_action_set_power_failure(self):
        """Test if an exception is thrown when the set_power call fails."""
        node = obj_utils.create_test_node(self.context,
                                          uuid=cmn_utils.generate_uuid(),
                                          driver='fake',
                                          power_state=states.POWER_OFF)
        task = task_manager.TaskManager(self.context, node.uuid)

        with mock.patch.object(self.driver.power,
                               'get_power_state') as get_power_mock:
            with mock.patch.object(self.driver.power,
                                   'set_power_state') as set_power_mock:
                get_power_mock.return_value = states.POWER_OFF
                set_power_mock.side_effect = exception.IronicException()

                self.assertRaises(
                    exception.IronicException,
                    conductor_utils.node_power_action,
                    task,
                    states.POWER_ON)

                node.refresh()
                get_power_mock.assert_called_once_with(mock.ANY)
                set_power_mock.assert_called_once_with(mock.ANY,
                                                       states.POWER_ON)
                self.assertEqual(states.POWER_OFF, node['power_state'])
                self.assertIsNone(node['target_power_state'])
                self.assertIsNotNone(node['last_error'])
示例#27
0
    def test_node_power_action_in_same_state(self):
        """Test setting node state to its present state.

        Test that we don't try to set the power state if the requested
        state is the same as the current state.
        """
        node = obj_utils.create_test_node(self.context,
                                          uuid=cmn_utils.generate_uuid(),
                                          driver='fake',
                                          last_error='anything but None',
                                          power_state=states.POWER_ON)
        task = task_manager.TaskManager(self.context, node.uuid)

        with mock.patch.object(self.driver.power,
                               'get_power_state') as get_power_mock:
            get_power_mock.return_value = states.POWER_ON

            with mock.patch.object(self.driver.power,
                                   'set_power_state') as set_power_mock:
                conductor_utils.node_power_action(task, states.POWER_ON)

                node.refresh()
                get_power_mock.assert_called_once_with(mock.ANY)
                self.assertFalse(set_power_mock.called,
                                 "set_power_state unexpectedly called")
                self.assertEqual(states.POWER_ON, node['power_state'])
                self.assertIsNone(node['target_power_state'])
                self.assertIsNone(node['last_error'])
示例#28
0
    def test_node_power_action_invalid_state(self):
        """Test for exception when changing to an invalid power state."""
        node = obj_utils.create_test_node(self.context,
                                          uuid=cmn_utils.generate_uuid(),
                                          driver='fake',
                                          power_state=states.POWER_ON)
        task = task_manager.TaskManager(self.context, node.uuid)

        with mock.patch.object(self.driver.power,
                               'get_power_state') as get_power_mock:
            get_power_mock.return_value = states.POWER_ON

            self.assertRaises(exception.InvalidParameterValue,
                              conductor_utils.node_power_action,
                              task,
                              "INVALID_POWER_STATE")

            node.refresh()
            get_power_mock.assert_called_once_with(mock.ANY)
            self.assertEqual(states.POWER_ON, node['power_state'])
            self.assertIsNone(node['target_power_state'])
            self.assertIsNotNone(node['last_error'])

            # last_error is cleared when a new transaction happens
            conductor_utils.node_power_action(task, states.POWER_OFF)
            node.refresh()
            self.assertEqual(states.POWER_OFF, node['power_state'])
            self.assertIsNone(node['target_power_state'])
            self.assertIsNone(node['last_error'])
示例#29
0
    def post(self, node):
        """Create a new node.

        :param node: a node within the request body.
        """
        if self._from_chassis:
            raise exception.OperationNotPermitted

        # NOTE(deva): get_topic_for checks if node.driver is in the hash ring
        #             and raises NoValidHost if it is not.
        #             We need to ensure that node has a UUID before it can
        #             be mapped onto the hash ring.
        if not node.uuid:
            node.uuid = utils.generate_uuid()

        try:
            pecan.request.rpcapi.get_topic_for(node)
        except exception.NoValidHost as e:
            # NOTE(deva): convert from 404 to 400 because client can see
            #             list of available drivers and shouldn't request
            #             one that doesn't exist.
            e.code = 400
            raise e

        new_node = pecan.request.dbapi.create_node(node.as_dict())

        return Node.convert_with_links(new_node)
示例#30
0
    def test_node_power_action_invalid_driver_info(self):
        """Test if an exception is thrown when the driver validation
        fails.
        """
        ndict = utils.get_test_node(uuid=cmn_utils.generate_uuid(),
                                    driver='fake',
                                    power_state=states.POWER_ON)
        node = self.dbapi.create_node(ndict)
        task = task_manager.TaskManager(self.context, node.uuid)

        with mock.patch.object(self.driver.power, 'validate') \
                as validate_mock:
            validate_mock.side_effect = exception.InvalidParameterValue(
                'wrong power driver info')

            self.assertRaises(exception.InvalidParameterValue,
                              conductor_utils.node_power_action,
                              task,
                              task.node,
                              states.POWER_ON)

            node.refresh(self.context)
            validate_mock.assert_called_once_with(mock.ANY, mock.ANY)
            self.assertEqual(node['power_state'], states.POWER_ON)
            self.assertIsNone(node['target_power_state'])
            self.assertIsNotNone(node['last_error'])