Beispiel #1
0
 def test_get_one_host(self, mock_get_by_uuid, mock_policy):
     mock_policy.return_value = True
     test_host = utils.get_test_compute_node()
     numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
     test_host['numa_topology'] = numat
     test_host_obj = objects.ComputeNode(self.context, **test_host)
     mock_get_by_uuid.return_value = test_host_obj
     response = self.get('/v1/hosts/%s' % test_host['uuid'])
     mock_get_by_uuid.assert_called_once_with(mock.ANY, test_host['uuid'])
     self.assertEqual(200, response.status_int)
     self.assertEqual(test_host['uuid'], response.json['uuid'])
Beispiel #2
0
 def test_get_one_host(self, mock_get_by_uuid, mock_policy):
     mock_policy.return_value = True
     test_host = utils.get_test_compute_node()
     numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
     test_host['numa_topology'] = numat
     test_host_obj = objects.ComputeNode(self.context, **test_host)
     mock_get_by_uuid.return_value = test_host_obj
     response = self.get('/v1/hosts/%s' % test_host['uuid'])
     mock_get_by_uuid.assert_called_once_with(
         mock.ANY,
         test_host['uuid'])
     self.assertEqual(200, response.status_int)
     self.assertEqual(test_host['uuid'],
                      response.json['uuid'])
Beispiel #3
0
def get_test_compute_node(context, **kwargs):
    """Return a test compute node 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_compute_node = db_utils.get_test_compute_node(**kwargs)
    compute_node = objects.ComputeNode(context)
    for key in db_compute_node:
        if key == 'numa_topology':
            numa_obj = NUMATopology._from_dict(db_compute_node[key])
            compute_node.numa_topology = numa_obj
        else:
            setattr(compute_node, key, db_compute_node[key])
    return compute_node
Beispiel #4
0
 def test_get_one_host(self, mock_get_by_uuid):
     test_host = utils.get_test_compute_node()
     numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
     test_host['numa_topology'] = numat
     test_host_obj = objects.ComputeNode(self.context, **test_host)
     mock_get_by_uuid.return_value = test_host_obj
     extra_environ = {'HTTP_ACCEPT': 'application/json'}
     headers = {'OpenStack-API-Version': 'container 1.4'}
     response = self.app.get('/v1/hosts/%s' % test_host['uuid'],
                             extra_environ=extra_environ,
                             headers=headers)
     mock_get_by_uuid.assert_called_once_with(
         mock.ANY,
         test_host['uuid'])
     self.assertEqual(200, response.status_int)
     self.assertEqual(test_host['uuid'],
                      response.json['uuid'])
Beispiel #5
0
    def test_get_all_hosts(self, mock_host_list, mock_policy):
        mock_policy.return_value = True
        test_host = utils.get_test_compute_node()
        numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
        test_host['numa_topology'] = numat
        hosts = [objects.ComputeNode(self.context, **test_host)]
        mock_host_list.return_value = hosts

        response = self.get('/v1/hosts')

        mock_host_list.assert_called_once_with(mock.ANY,
                                               1000, None, 'hostname', 'asc',
                                               filters=None)
        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(test_host['uuid'],
                         actual_hosts[0].get('uuid'))
Beispiel #6
0
    def test_get_all_hosts(self, mock_host_list, mock_policy):
        mock_policy.return_value = True
        test_host = utils.get_test_compute_node()
        numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
        test_host['numa_topology'] = numat
        hosts = [objects.ComputeNode(self.context, **test_host)]
        mock_host_list.return_value = hosts

        response = self.get('/v1/hosts')

        mock_host_list.assert_called_once_with(mock.ANY,
                                               1000, None, 'hostname', 'asc',
                                               filters=None)
        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(test_host['uuid'],
                         actual_hosts[0].get('uuid'))
Beispiel #7
0
    def test_get_all_hosts(self, mock_host_list):
        test_host = utils.get_test_compute_node()
        numat = numa.NUMATopology._from_dict(test_host['numa_topology'])
        test_host['numa_topology'] = numat
        hosts = [objects.ComputeNode(self.context, **test_host)]
        mock_host_list.return_value = hosts

        extra_environ = {'HTTP_ACCEPT': 'application/json'}
        headers = {'OpenStack-API-Version': 'container 1.4'}
        response = self.app.get('/v1/hosts', extra_environ=extra_environ,
                                headers=headers)

        mock_host_list.assert_called_once_with(mock.ANY,
                                               1000, None, 'hostname', 'asc',
                                               filters=None)
        self.assertEqual(200, response.status_int)
        actual_hosts = response.json['hosts']
        self.assertEqual(1, len(actual_hosts))
        self.assertEqual(test_host['uuid'],
                         actual_hosts[0].get('uuid'))
Beispiel #8
0
 def setUp(self):
     super(TestComputeNodeObject, self).setUp()
     self.fake_numa_topology = utils.get_test_numa_topology()
     self.fake_compute_node = utils.get_test_compute_node(
         numa_topology=self.fake_numa_topology)