示例#1
0
    def test_expire_lease(self, client_mock):
        client_mock.return_value.node.get.return_value.provision_state = (
            'active')

        with mock.patch.object(ironic_node.IronicNode,
                               'get_lease_uuid',
                               autospec=True) as mock_lease_uuid_true:
            fake_lease = FakeLease()
            mock_lease_uuid_true.return_value = fake_lease.uuid
            with mock.patch.object(ironic_node.IronicNode,
                                   'get_project_id',
                                   autospec=True) as mock_project_id_get:
                mock_project_id_get.return_value = fake_lease.project_id

                test_ironic_node = ironic_node.IronicNode(fake_uuid)
                test_ironic_node.expire_lease(fake_lease)

                mock_project_id_get.assert_called_once()
                mock_lease_uuid_true.assert_called_once()
                self.assertEqual(client_mock.call_count, 3)
                client_mock.return_value.node.update.assert_called_once()
                client_mock.return_value.node.get.assert_called_once_with(
                    test_ironic_node._uuid)
                client_mock.return_value.node.set_provision_state.\
                    assert_called_once_with(test_ironic_node._uuid, 'deleted')

        with mock.patch.object(ironic_node.IronicNode,
                               'get_lease_uuid',
                               autospec=True) as mock_lease_uuid_false:
            mock_lease_uuid_false.return_value = 'none'
            test_ironic_node = ironic_node.IronicNode(fake_uuid)
            fake_lease = FakeLease()
            test_ironic_node.expire_lease(fake_lease)
            mock_lease_uuid_false.assert_called_once()
示例#2
0
 def test_get_by_name(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode('node-name')
     self.assertEqual(fake_uuid, test_ironic_node.get_resource_uuid())
     client_mock.assert_called_once()
     client_mock.return_value.node.get.assert_called_once_with('node-name')
 def get_resource_object(resource_type, resource_uuid):
     if resource_type == 'ironic_node':
         return ironic_node.IronicNode(resource_uuid)
     elif resource_type == 'dummy_node':
         return dummy_node.DummyNode(resource_uuid)
     elif resource_type == 'test_node':
         return test_node.TestNode(resource_uuid)
     raise exception.ResourceTypeUnknown(resource_type=resource_type)
示例#4
0
    def test_verify_availability_for_offer(self, mock_rva):
        start = self.base_time
        end = self.base_time + datetime.timedelta(days=10)
        fake_uuid = uuidutils.generate_uuid()
        test_node = ironic_node.IronicNode(fake_uuid)

        test_node.verify_availability(start, end)
        mock_rva.assert_called_once_with('ironic_node', fake_uuid, start, end)
示例#5
0
    def test_get_resource_name(self, mock_gnn):
        mock_gnn.return_value = 'node-name'
        test_ironic_node = ironic_node.IronicNode(fake_uuid)

        resource_name = test_ironic_node.get_resource_name()

        self.assertEqual('node-name', resource_name)
        mock_gnn.assert_called_once_with(fake_uuid, None)
示例#6
0
 def test_get_project_id(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     project_id = test_ironic_node.get_project_id()
     expected_project_id = fake_get_node.lessee
     self.assertEqual(project_id, expected_project_id)
     client_mock.assert_called_once()
     client_mock.return_value.node.get.assert_called_once_with(
         test_ironic_node._uuid)
示例#7
0
 def test_get_lease_uuid(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     lease_uuid = test_ironic_node.get_lease_uuid()
     expected_lease_uuid = fake_get_node.properties.get('lease_uuid')
     self.assertEqual(lease_uuid, expected_lease_uuid)
     client_mock.assert_called_once()
     client_mock.return_value.node.get.assert_called_once_with(
         test_ironic_node._uuid)
示例#8
0
 def test_get_resource_class(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     resource_class = test_ironic_node.get_resource_class()
     expected_resource_class = fake_get_node.resource_class
     self.assertEqual(resource_class, expected_resource_class)
     client_mock.assert_called_once()
     client_mock.return_value.node.get.assert_called_once_with(
         test_ironic_node._uuid)
示例#9
0
 def test_get_node_config(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     config = test_ironic_node.get_node_config()
     expected_config = fake_get_node.properties
     expected_config.pop('lease_uuid', None)
     self.assertEqual(config, expected_config)
     client_mock.assert_called_once()
     client_mock.return_value.node.get.assert_called_once_with(
         test_ironic_node._uuid)
示例#10
0
 def test_get_resource_uuid(self):
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     self.assertEqual(fake_uuid, test_ironic_node.get_resource_uuid())
示例#11
0
 def test_resource_type(self):
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     self.assertEqual('ironic_node', test_ironic_node.resource_type)
示例#12
0
 def test_resource_admin_project_id(self, client_mock):
     fake_get_node = FakeIronicNode()
     client_mock.return_value.node.get.return_value = fake_get_node
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     self.assertEqual(self.fake_admin_project_id_2,
                      test_ironic_node.resource_admin_project_id())
示例#13
0
 def test_set_lease(self, client_mock):
     test_ironic_node = ironic_node.IronicNode(fake_uuid)
     fake_lease = FakeLease()
     test_ironic_node.set_lease(fake_lease)
     client_mock.assert_called_once()
     client_mock.return_value.node.update.assert_called_once()