Beispiel #1
0
 def test_create_compute_node_already_exists(self):
     utils.create_test_compute_node(
         context=self.context, uuid='123')
     with self.assertRaisesRegex(exception.ComputeNodeAlreadyExists,
                                 'A compute node with UUID 123.*'):
         utils.create_test_compute_node(
             context=self.context, uuid='123')
Beispiel #2
0
    def test_list_compute_nodes_with_filters(self):
        node1 = utils.create_test_compute_node(
            hostname='node-one',
            uuid=uuidutils.generate_uuid(),
            context=self.context)
        node2 = utils.create_test_compute_node(
            hostname='node-two',
            uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'node-one'})
        self.assertEqual([node1.uuid], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'node-two'})
        self.assertEqual([node2.uuid], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'bad-node'})
        self.assertEqual([], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context,
            filters={'hostname': node1.hostname})
        self.assertEqual([node1.uuid], [r.uuid for r in res])
Beispiel #3
0
 def test_create_compute_node_already_exists(self):
     utils.create_test_compute_node(
         context=self.context, uuid='123')
     with self.assertRaisesRegex(exception.ComputeNodeAlreadyExists,
                                 'A compute node with UUID 123.*'):
         utils.create_test_compute_node(
             context=self.context, uuid='123')
Beispiel #4
0
    def test_list_compute_nodes_with_filters(self):
        node1 = utils.create_test_compute_node(
            hostname='node-one',
            uuid=uuidutils.generate_uuid(),
            rp_uuid=uuidutils.generate_uuid(),
            context=self.context)
        node2 = utils.create_test_compute_node(
            hostname='node-two',
            uuid=uuidutils.generate_uuid(),
            rp_uuid=uuidutils.generate_uuid(),
            context=self.context)

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'node-one'})
        self.assertEqual([node1.uuid], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'node-two'})
        self.assertEqual([node2.uuid], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context, filters={'hostname': 'bad-node'})
        self.assertEqual([], [r.uuid for r in res])

        res = dbapi.list_compute_nodes(
            self.context,
            filters={'hostname': node1.hostname})
        self.assertEqual([node1.uuid], [r.uuid for r in res])
Beispiel #5
0
 def test_create_compute_node_already_exists(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     utils.create_test_compute_node(context=self.context, hostname='123')
     mock_read.side_effect = lambda *args: None
     self.assertRaises(exception.ResourceExists,
                       utils.create_test_compute_node,
                       context=self.context,
                       hostname='123')
Beispiel #6
0
 def test_update_compute_node_uuid(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(
         context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_compute_node,
                       self.context, compute_node.uuid,
                       {'uuid': ''})
Beispiel #7
0
 def test_destroy_compute_node(self, mock_delete, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(compute_node.
                                                          as_dict())
     dbapi.destroy_compute_node(self.context, compute_node.uuid)
     mock_delete.assert_called_once_with('/compute_nodes/%s' %
                                         compute_node.uuid)
Beispiel #8
0
 def test_get_compute_node_by_uuid(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(compute_node.
                                                          as_dict())
     res = dbapi.get_compute_node(self.context, compute_node.uuid)
     self.assertEqual(compute_node.uuid, res.uuid)
     self.assertEqual(compute_node.hostname, res.hostname)
Beispiel #9
0
    def test_update_compute_node(self):
        node = utils.create_test_compute_node(context=self.context)
        old_hostname = node.hostname
        new_hostname = 'new-hostname'
        self.assertNotEqual(old_hostname, new_hostname)

        res = dbapi.update_compute_node(
            self.context, node.uuid, {'hostname': new_hostname})
        self.assertEqual(new_hostname, res.hostname)
Beispiel #10
0
    def test_update_compute_node(self):
        node = utils.create_test_compute_node(context=self.context)
        old_hostname = node.hostname
        new_hostname = 'new-hostname'
        self.assertNotEqual(old_hostname, new_hostname)

        res = dbapi.update_compute_node(
            self.context, node.uuid, {'hostname': new_hostname})
        self.assertEqual(new_hostname, res.hostname)
Beispiel #11
0
 def test_get_compute_node_by_name(self, mock_db_inst,
                                   mock_write, mock_read):
     mock_db_inst.return_value = etcdapi.get_backend()
     mock_read.side_effect = etcd.EtcdKeyNotFound
     node = utils.create_test_compute_node(context=self.context)
     mock_read.side_effect = lambda *args: FakeEtcdResult(
         node.as_dict())
     res = dbapi.get_compute_node(self.context, node.hostname)
     self.assertEqual(node.uuid, res.uuid)
Beispiel #12
0
 def test_list_compute_nodes(self):
     uuids = []
     for i in range(1, 6):
         node = utils.create_test_compute_node(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             hostname='node' + str(i))
         uuids.append(six.text_type(node['uuid']))
     res = dbapi.list_compute_nodes(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Beispiel #13
0
 def test_list_compute_nodes(self):
     uuids = []
     for i in range(1, 6):
         node = utils.create_test_compute_node(
             uuid=uuidutils.generate_uuid(),
             context=self.context,
             hostname='node' + str(i))
         uuids.append(six.text_type(node['uuid']))
     res = dbapi.list_compute_nodes(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(sorted(uuids), sorted(res_uuids))
Beispiel #14
0
 def test_update_compute_node(self, mock_update, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     compute_node = utils.create_test_compute_node(context=self.context)
     old_name = compute_node.hostname
     new_name = 'new-name'
     self.assertNotEqual(old_name, new_name)
     mock_read.side_effect = lambda *args: FakeEtcdResult(compute_node.
                                                          as_dict())
     dbapi.update_compute_node(self.context, compute_node.uuid,
                               {'hostname': new_name})
     self.assertEqual(
         new_name,
         json.loads(mock_update.call_args_list[0][0][0].value)['hostname'])
Beispiel #15
0
 def test_list_compute_nodes_sorted(self, mock_write, mock_read):
     hostnames = []
     compute_nodes = []
     mock_read.side_effect = etcd.EtcdKeyNotFound
     for i in range(1, 6):
         res_class = utils.create_test_compute_node(context=self.context,
                                                    hostname='class' +
                                                    str(i))
         compute_nodes.append(res_class.as_dict())
         hostnames.append(six.text_type(res_class['hostname']))
     mock_read.side_effect = lambda *args: FakeEtcdMultipleResult(
         compute_nodes)
     res = dbapi.list_compute_nodes(self.context, sort_key='hostname')
     res_names = [r.hostname for r in res]
     self.assertEqual(sorted(hostnames), res_names)
Beispiel #16
0
    def test_list_compute_nodes_sorted(self):
        uuids = []
        for i in range(5):
            node = utils.create_test_compute_node(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                hostname='node' + str(i))
            uuids.append(six.text_type(node.uuid))
        res = dbapi.list_compute_nodes(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_compute_nodes,
                          self.context,
                          sort_key='foo')
Beispiel #17
0
    def test_list_compute_nodes_sorted(self):
        uuids = []
        for i in range(5):
            node = utils.create_test_compute_node(
                uuid=uuidutils.generate_uuid(),
                context=self.context,
                hostname='node' + str(i))
            uuids.append(six.text_type(node.uuid))
        res = dbapi.list_compute_nodes(self.context, sort_key='uuid')
        res_uuids = [r.uuid for r in res]
        self.assertEqual(sorted(uuids), res_uuids)

        self.assertRaises(exception.InvalidParameterValue,
                          dbapi.list_compute_nodes,
                          self.context,
                          sort_key='foo')
Beispiel #18
0
    def test_get_all_hosts_with_pagination_marker(self, mock_host_list,
                                                  mock_policy):
        mock_policy.return_value = True
        host_list = []
        for id_ in range(4):
            test_host = utils.create_test_compute_node(
                context=self.context, uuid=uuidutils.generate_uuid())
            numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
            test_host['numa_topology'] = numat
            host = objects.ComputeNode(self.context, **test_host)
            host_list.append(host)
        mock_host_list.return_value = host_list[-1:]
        response = self.get('/v1/hosts?limit=3&marker=%s' % host_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(host_list[-1].uuid, actual_hosts[0].get('uuid'))
Beispiel #19
0
    def test_get_all_hosts_with_pagination_marker(self, mock_host_list,
                                                  mock_policy):
        mock_policy.return_value = True
        host_list = []
        for id_ in range(4):
            test_host = utils.create_test_compute_node(
                context=self.context,
                uuid=uuidutils.generate_uuid())
            numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
            test_host['numa_topology'] = numat
            host = objects.ComputeNode(self.context, **test_host)
            host_list.append(host)
        mock_host_list.return_value = host_list[-1:]
        response = self.get('/v1/hosts?limit=3&marker=%s'
                            % host_list[2].uuid)

        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(host_list[-1].uuid,
                         actual_hosts[0].get('uuid'))
Beispiel #20
0
    def test_get_all_hosts_with_pagination_marker(self, mock_host_list):
        host_list = []
        for id_ in range(4):
            test_host = utils.create_test_compute_node(
                context=self.context,
                uuid=uuidutils.generate_uuid())
            numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
            test_host['numa_topology'] = numat
            host = objects.ComputeNode(self.context, **test_host)
            host_list.append(host)
        mock_host_list.return_value = host_list[-1:]
        extra_environ = {'HTTP_ACCEPT': 'application/json'}
        headers = {'OpenStack-API-Version': 'container 1.4'}
        response = self.app.get('/v1/hosts?limit=3&marker=%s'
                                % host_list[2].uuid,
                                extra_environ=extra_environ, headers=headers)

        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(host_list[-1].uuid,
                         actual_hosts[0].get('uuid'))
Beispiel #21
0
 def test_destroy_compute_node_by_uuid(self):
     node = utils.create_test_compute_node(context=self.context)
     dbapi.destroy_compute_node(self.context, node.uuid)
     self.assertRaises(exception.ComputeNodeNotFound,
                       dbapi.get_compute_node,
                       self.context, node.uuid)
Beispiel #22
0
 def test_get_compute_node_by_hostname(self):
     node = utils.create_test_compute_node(context=self.context)
     res = dbapi.get_compute_node_by_hostname(
         self.context, node.hostname)
     self.assertEqual(node.uuid, res.uuid)
     self.assertEqual(node.hostname, res.hostname)
Beispiel #23
0
 def test_update_compute_node_uuid(self):
     node = utils.create_test_compute_node(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_compute_node, self.context,
                       node.uuid, {'uuid': ''})
Beispiel #24
0
 def test_create_compute_node(self):
     utils.create_test_compute_node(context=self.context)
Beispiel #25
0
 def test_update_compute_node_uuid(self):
     node = utils.create_test_compute_node(context=self.context)
     self.assertRaises(exception.InvalidParameterValue,
                       dbapi.update_compute_node, self.context,
                       node.uuid, {'uuid': ''})
Beispiel #26
0
 def test_create_compute_node(self):
     utils.create_test_compute_node(context=self.context)
Beispiel #27
0
 def test_destroy_compute_node_by_uuid(self):
     node = utils.create_test_compute_node(context=self.context)
     dbapi.destroy_compute_node(self.context, node.uuid)
     self.assertRaises(exception.ComputeNodeNotFound,
                       dbapi.get_compute_node,
                       self.context, node.uuid)
Beispiel #28
0
 def test_get_compute_node_by_hostname(self):
     node = utils.create_test_compute_node(context=self.context)
     res = dbapi.get_compute_node_by_hostname(
         self.context, node.hostname)
     self.assertEqual(node.uuid, res.uuid)
     self.assertEqual(node.hostname, res.hostname)
Beispiel #29
0
 def test_create_compute_node(self, mock_write, mock_read):
     mock_read.side_effect = etcd.EtcdKeyNotFound
     utils.create_test_compute_node(context=self.context)