def test_delete_reservation_provider(self, kss_req):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"
        get_json_mock = {
            'resource_providers': [{
                'uuid': rp_uuid,
                'name': rp_name,
                'generation': 0,
                'parent_provider_uuid': host_uuid
            }]
        }
        mock_call1 = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(get_json_mock))
        mock_call2 = fake_requests.FakeResponse(200)
        kss_req.side_effect = [mock_call1, mock_call2]

        self.client.delete_reservation_provider(host_name)

        expected_url_get = "/resource_providers?name=%s" % rp_name
        self._assert_keystone_called_any(kss_req, expected_url_get, 'GET')

        expected_url_post = "/resource_providers/%s" % rp_uuid
        self._assert_keystone_called_any(kss_req, expected_url_post, 'DELETE')
Example #2
0
    def test_create_reservation_provider(self, kss_req):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"
        get_json_mock = {
            'resource_providers': [{
                'uuid': host_uuid,
                'name': host_name,
                'generation': 0,
                'parent_provider_uuid': None
            }]
        }
        post_json_mock = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        mock_call1 = fake_requests.FakeResponse(
            200, content=json.dumps(get_json_mock))
        mock_call2 = fake_requests.FakeResponse(
            200, content=json.dumps(post_json_mock))
        kss_req.side_effect = [mock_call1, mock_call2]

        self.client.create_reservation_provider(host_name)

        expected_url_get = "/resource_providers?name=%s" % host_name
        kss_req.assert_any_call(expected_url_get,
                                'GET',
                                endpoint_filter={
                                    'service_type': 'placement',
                                    'interface': 'public'
                                },
                                headers={'accept': 'application/json'},
                                microversion=PLACEMENT_MICROVERSION,
                                raise_exc=False)

        expected_url_post = "/resource_providers"
        kss_req.assert_any_call(expected_url_post,
                                'POST',
                                endpoint_filter={
                                    'service_type': 'placement',
                                    'interface': 'public'
                                },
                                json={
                                    'name': 'blazar_compute-1',
                                    'parent_provider_uuid': host_uuid
                                },
                                headers={'accept': 'application/json'},
                                microversion=PLACEMENT_MICROVERSION,
                                raise_exc=False)
    def test_create_resource_provider(self, kss_req):
        rp_name = 'Blazar'
        rp_uuid = uuidutils.generate_uuid()
        parent_uuid = uuidutils.generate_uuid()

        mock_json_data = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': parent_uuid
        }

        kss_req.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_json_data))

        result = self.client.create_resource_provider(rp_name,
                                                      rp_uuid=rp_uuid,
                                                      parent_uuid=parent_uuid)

        expected_url = '/resource_providers'
        expected_data = {
            'uuid': rp_uuid,
            'name': rp_name,
            'parent_provider_uuid': parent_uuid
        }
        self._assert_keystone_called_once(kss_req,
                                          expected_url,
                                          'POST',
                                          json=expected_data)
        self.assertEqual(mock_json_data, result)
 def test_put(self, kss_req):
     kss_req.return_value = fake_requests.FakeResponse(200)
     url = '/resource_providers'
     data = {'name': 'unicorn'}
     resp = self.client.put(url, data)
     self.assertEqual(200, resp.status_code)
     self._assert_keystone_called_once(kss_req, url, 'PUT', json=data)
Example #5
0
    def test_create_resource_provider(self, kss_req):
        rp_name = 'Blazar'
        rp_uuid = uuidutils.generate_uuid()
        parent_uuid = uuidutils.generate_uuid()

        mock_json_data = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': parent_uuid
        }

        kss_req.return_value = fake_requests.FakeResponse(
            200, content=json.dumps(mock_json_data))

        result = self.client.create_resource_provider(rp_name,
                                                      rp_uuid=rp_uuid,
                                                      parent_uuid=parent_uuid)

        expected_url = '/resource_providers'
        kss_req.assert_called_once_with(expected_url,
                                        'POST',
                                        json={
                                            'uuid': rp_uuid,
                                            'name': rp_name,
                                            'parent_provider_uuid': parent_uuid
                                        },
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
        self.assertEqual(mock_json_data, result)
Example #6
0
    def test_delete_reservation_inventory(self, kss_req, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock of current resource provider
        mock_get_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        get_rp.return_value = mock_get_rp_json

        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_reservation_inventory(host_name, "curr1")

        expected_url = ('/resource_providers/%s/inventories'
                        '/CUSTOM_RESERVATION_CURR1' % rp_uuid)

        kss_req.assert_called_once_with(expected_url,
                                        'DELETE',
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
    def test_delete_reservation_provider_no_rp(self, kss_req):
        host_name = "compute-1"
        rp_name = "blazar_compute-1"
        get_json_mock = {'resource_providers': []}
        mock_call1 = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(get_json_mock))
        mock_call2 = fake_requests.FakeResponse(200)
        kss_req.side_effect = [mock_call1, mock_call2]

        self.client.delete_reservation_provider(host_name)

        expected_url_get = "/resource_providers?name=%s" % rp_name
        self._assert_keystone_called_any(kss_req, expected_url_get, 'GET')

        # Ensure that mock_call2 for delete is not called
        self.assertEqual(kss_req.call_count, 1)
 def test_create_reservation_provider_fail(self, kss_req):
     host_name = "compute-1"
     get_json_mock = {'resource_providers': []}
     kss_req.return_value = fake_requests.FakeResponse(
         200, content=jsonutils.dump_as_bytes(get_json_mock))
     self.assertRaises(exceptions.ResourceProviderNotFound,
                       self.client.create_reservation_provider, host_name)
    def test_get_resource_provider(self, kss_req):
        rp_name = 'blazar'
        rp_uuid = uuidutils.generate_uuid()
        parent_uuid = uuidutils.generate_uuid()

        mock_json_data = {
            'resource_providers': [{
                'uuid': rp_uuid,
                'name': rp_name,
                'generation': 0,
                'parent_provider_uuid': parent_uuid
            }]
        }

        kss_req.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_json_data))

        result = self.client.get_resource_provider(rp_name)

        expected_url = '/resource_providers?name=blazar'
        self._assert_keystone_called_once(kss_req, expected_url, 'GET')
        expected = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': parent_uuid
        }
        self.assertEqual(expected, result)
    def test_delete_reservation_class(self, kss_req):
        rc_name = 'abc-def'
        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_reservation_class(rc_name)

        expected_url = '/resource_classes/CUSTOM_RESERVATION_ABC_DEF'
        self._assert_keystone_called_once(kss_req, expected_url, 'DELETE')
    def test_delete_resource_provider(self, kss_req):
        rp_uuid = uuidutils.generate_uuid()
        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_resource_provider(rp_uuid)

        expected_url = '/resource_providers/' + str(rp_uuid)
        self._assert_keystone_called_once(kss_req, expected_url, 'DELETE')
    def test_create_reservation_class(self, kss_req):
        rc_name = 'abc-def'
        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.create_reservation_class(rc_name)

        expected_url = '/resource_classes'
        expected_data = {'name': 'CUSTOM_RESERVATION_ABC_DEF'}
        self._assert_keystone_called_once(kss_req,
                                          expected_url,
                                          'POST',
                                          json=expected_data)
    def test_get_resource_provider_no_rp(self, kss_req):
        rp_name = 'blazar'

        mock_json_data = {'resource_providers': []}

        kss_req.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_json_data))

        result = self.client.get_resource_provider(rp_name)

        expected_url = '/resource_providers?name=blazar'
        self._assert_keystone_called_once(kss_req, expected_url, 'GET')
        self.assertEqual(None, result)
Example #14
0
 def test_delete(self, kss_req):
     kss_req.return_value = fake_requests.FakeResponse(200)
     url = '/resource_providers'
     resp = self.client.delete(url)
     self.assertEqual(200, resp.status_code)
     kss_req.assert_called_once_with(url,
                                     'DELETE',
                                     endpoint_filter={
                                         'service_type': 'placement',
                                         'interface': 'public'
                                     },
                                     headers={'accept': 'application/json'},
                                     microversion=PLACEMENT_MICROVERSION,
                                     raise_exc=False)
Example #15
0
    def test_delete_reservation_provider_no_rp(self, kss_req):
        host_name = "compute-1"
        rp_name = "blazar_compute-1"
        get_json_mock = {'resource_providers': []}
        mock_call1 = fake_requests.FakeResponse(
            200, content=json.dumps(get_json_mock))
        mock_call2 = fake_requests.FakeResponse(200)
        kss_req.side_effect = [mock_call1, mock_call2]

        self.client.delete_reservation_provider(host_name)

        expected_url_get = "/resource_providers?name=%s" % rp_name
        kss_req.assert_any_call(expected_url_get,
                                'GET',
                                endpoint_filter={
                                    'service_type': 'placement',
                                    'interface': 'public'
                                },
                                headers={'accept': 'application/json'},
                                microversion=PLACEMENT_MICROVERSION,
                                raise_exc=False)

        # Ensure that mock_call2 for delete is not called
        self.assertEqual(kss_req.call_count, 1)
Example #16
0
    def test_delete_reservation_class(self, kss_req):
        rc_name = 'abc-def'
        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_reservation_class(rc_name)

        expected_url = '/resource_classes/CUSTOM_RESERVATION_ABC_DEF'
        kss_req.assert_called_once_with(expected_url,
                                        'DELETE',
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
Example #17
0
    def test_delete_resource_provider(self, kss_req):
        rp_uuid = uuidutils.generate_uuid()
        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_resource_provider(rp_uuid)

        expected_url = '/resource_providers/' + str(rp_uuid)
        kss_req.assert_called_once_with(expected_url,
                                        'DELETE',
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
Example #18
0
    def test_delete_reservation_inventory_no_rc(self, kss_req, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock of current resource provider
        mock_get_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        get_rp.return_value = mock_get_rp_json

        # If no reservation class found or if no inventory found,
        # then the placement API returns 404 error.
        kss_req.return_value = fake_requests.FakeResponse(404)
        # Ensure that no error is raised
        self.client.delete_reservation_inventory(host_name, "curr1")
Example #19
0
    def test_get_resource_provider_no_rp(self, kss_req):
        rp_name = 'blazar'

        mock_json_data = {'resource_providers': []}

        kss_req.return_value = fake_requests.FakeResponse(
            200, content=json.dumps(mock_json_data))

        result = self.client.get_resource_provider(rp_name)

        expected_url = '/resource_providers?name=blazar'
        kss_req.assert_called_once_with(expected_url,
                                        'GET',
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
        self.assertEqual(None, result)
    def test_delete_reservation_inventory(self, kss_req, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock of current resource provider
        mock_get_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        get_rp.return_value = mock_get_rp_json

        kss_req.return_value = fake_requests.FakeResponse(200)

        self.client.delete_reservation_inventory(host_name, "curr1")

        expected_url = ('/resource_providers/%s/inventories'
                        '/CUSTOM_RESERVATION_CURR1' % rp_uuid)

        self._assert_keystone_called_once(kss_req, expected_url, 'DELETE')
    def test_add_reservation_inventory(self, kss_req, client_get, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock of current resource provider
        mock_get_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        get_rp.return_value = mock_get_rp_json

        # Build the mock of "current" inventory for get_inventory()
        curr_gen = 11
        mock_get_inv_json = {
            'inventories': {
                'CUSTOM_RESERVATION_CURR': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 1
                },
            },
            "resource_provider_generation": curr_gen
        }
        client_get.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_get_inv_json))

        # Build the mock of "updated" inventory for update_inventory()
        update_gen = 12
        mock_put_json = {
            'inventories': {
                'CUSTOM_RESERVATION_CURR': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                },
            },
            "resource_provider_generation": update_gen
        }
        kss_req.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_put_json))

        result = self.client.update_reservation_inventory(host_name,
                                                          'curr',
                                                          2,
                                                          additional=True)

        expected_data = {
            'inventories': {
                'CUSTOM_RESERVATION_CURR': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                }
            },
            "resource_provider_generation": curr_gen
        }
        expected_url = '/resource_providers/%s/inventories' % rp_uuid
        self._assert_keystone_called_once(kss_req,
                                          expected_url,
                                          'PUT',
                                          json=expected_data)
        self.assertEqual(mock_put_json, result)
Example #22
0
    def test_update_reservation_inventory_no_rp(self, kss_req, client_get,
                                                create_rp, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock that there is no existing reservation provider
        get_rp.return_value = None

        # Build the mock of created resource provider
        mock_post_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        create_rp.return_value = mock_post_rp_json

        # Build the mock of "current" inventory for get_inventory()
        curr_gen = 0
        mock_get_inv_json = {
            'inventories': {},
            "resource_provider_generation": curr_gen
        }
        client_get.return_value = fake_requests.FakeResponse(
            200, content=json.dumps(mock_get_inv_json))

        # Build the mock of "updated" inventory for update_inventory()
        update_gen = 1
        mock_put_json = {
            'inventories': {
                'CUSTOM_RESERVATION_ADD': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                },
            },
            "resource_provider_generation": update_gen
        }
        kss_req.return_value = fake_requests.FakeResponse(
            200, content=json.dumps(mock_put_json))

        result = self.client.update_reservation_inventory(host_name, 'add', 3)

        # Ensure that the create_reservation_provider() is called.
        create_rp.assert_called_once_with(host_name)

        expected_data = {
            'inventories': {
                'CUSTOM_RESERVATION_ADD': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                },
            },
            "resource_provider_generation": curr_gen
        }
        expected_url = '/resource_providers/%s/inventories' % rp_uuid
        kss_req.assert_called_once_with(expected_url,
                                        'PUT',
                                        json=expected_data,
                                        endpoint_filter={
                                            'service_type': 'placement',
                                            'interface': 'public'
                                        },
                                        headers={'accept': 'application/json'},
                                        microversion=PLACEMENT_MICROVERSION,
                                        raise_exc=False)
        self.assertEqual(mock_put_json, result)
Example #23
0
 def test_delete_reservation_class_fail(self, kss_req):
     rc_name = 'abc-def'
     # If no reservation class found, the placement API returns 404 error.
     kss_req.return_value = fake_requests.FakeResponse(404)
     # Ensure that no error is raised
     self.client.delete_reservation_class(rc_name)
Example #24
0
    def test_create_reservation_class_fail(self, kss_req):
        rc_name = 'abc-def'
        kss_req.return_value = fake_requests.FakeResponse(400)

        self.assertRaises(exceptions.ResourceClassCreationFailed,
                          self.client.create_reservation_class, rc_name)
    def test_update_reservation_inventory_no_rp(self, kss_req, client_get,
                                                create_rp, get_rp):
        host_uuid = uuidutils.generate_uuid()
        host_name = "compute-1"
        rp_uuid = uuidutils.generate_uuid()
        rp_name = "blazar_compute-1"

        # Build the mock that there is no existing reservation provider
        get_rp.return_value = None

        # Build the mock of created resource provider
        mock_post_rp_json = {
            'uuid': rp_uuid,
            'name': rp_name,
            'generation': 0,
            'parent_provider_uuid': host_uuid
        }
        create_rp.return_value = mock_post_rp_json

        # Build the mock of "current" inventory for get_inventory()
        curr_gen = 0
        mock_get_inv_json = {
            'inventories': {},
            "resource_provider_generation": curr_gen
        }
        client_get.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_get_inv_json))

        # Build the mock of "updated" inventory for update_inventory()
        update_gen = 1
        mock_put_json = {
            'inventories': {
                'CUSTOM_RESERVATION_ADD': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                },
            },
            "resource_provider_generation": update_gen
        }
        kss_req.return_value = fake_requests.FakeResponse(
            200, content=jsonutils.dump_as_bytes(mock_put_json))

        result = self.client.update_reservation_inventory(host_name, 'add', 3)

        # Ensure that the create_reservation_provider() is called.
        create_rp.assert_called_once_with(host_name)

        expected_data = {
            'inventories': {
                'CUSTOM_RESERVATION_ADD': {
                    "allocation_ratio": 1.0,
                    "max_unit": 1,
                    "min_unit": 1,
                    "reserved": 0,
                    "step_size": 1,
                    "total": 3
                },
            },
            "resource_provider_generation": curr_gen
        }
        expected_url = '/resource_providers/%s/inventories' % rp_uuid
        self._assert_keystone_called_once(kss_req,
                                          expected_url,
                                          'PUT',
                                          json=expected_data)
        self.assertEqual(mock_put_json, result)
Example #26
0
    def test_delete_resource_provider_fail(self, kss_req):
        rp_uuid = uuidutils.generate_uuid()
        kss_req.return_value = fake_requests.FakeResponse(404)

        self.assertRaises(exceptions.ResourceProviderDeletionFailed,
                          self.client.delete_resource_provider, rp_uuid)
Example #27
0
    def test_create_resource_provider_fail(self, kss_req):
        rp_name = 'Blazar'
        kss_req.return_value = fake_requests.FakeResponse(404)

        self.assertRaises(exceptions.ResourceProviderCreationFailed,
                          self.client.create_resource_provider, rp_name)
Example #28
0
    def test_get_resource_provider_fail(self, kss_req):
        rp_name = 'blazar'
        kss_req.return_value = fake_requests.FakeResponse(404)

        self.assertRaises(exceptions.ResourceProviderRetrievalFailed,
                          self.client.get_resource_provider, rp_name)
 def test_delete(self, kss_req):
     kss_req.return_value = fake_requests.FakeResponse(200)
     url = '/resource_providers'
     resp = self.client.delete(url)
     self.assertEqual(200, resp.status_code)
     self._assert_keystone_called_once(kss_req, url, 'DELETE')