def test_external_storage_resource_block(self):
        with open(
            'oneview_redfish_toolkit/mockups/redfish/'
            'VolumesResourceBlock.json'
        ) as f:
            expected_storage_details = json.load(f)

        volume_obj = Volumes(self.oneview_client, self.volume[0])
        self.oneview_client.volumes.get_by_id.return_value = volume_obj

        storage_pool = {
            "uri": "/rest/storage-pools/DC8BD64B-9A4E-4722-92D3-A9F4015B0B71",
            "deviceSpecificAttributes": {"supportedRAIDLevel": "RAID6"}
        }
        storage_pools_obj = StoragePools(self.oneview_client, storage_pool)
        self.oneview_client.storage_pools.get_by_uri.return_value = storage_pools_obj

        response = self.client.get(
            "/redfish/v1/CompositionService/ResourceBlocks"
            "/B526F59E-9BC7-467F-9205-A9F4015CE296/Storage/1/Volumes/1")

        result = json.loads(response.data.decode("utf-8"))
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(expected_storage_details, result)
    def storage_pools(self):
        """
        Gets the StoragePools API client.

        Returns:
            StoragePools:
        """
        return StoragePools(self.__connection)
    def storage_pools(self):
        """
        Gets the StoragePools API client.

        Returns:
            StoragePools:
        """
        if not self.__storage_pools:
            self.__storage_pools = StoragePools(self.__connection)
        return self.__storage_pools
    def test_create_when_power_off_on_compose_is_not_configured(
            self, config_mock, power_state):
        """Tests create when power_off is blank, should below a normal flow"""

        with open('oneview_redfish_toolkit/mockups/oneview/'
                  'ServerProfileBuiltFromTemplateToCreateASystem.json') as f:
            expected_server_profile_built = json.load(f)

        expected_server_profile_built["sanStorage"] = self.san_storage

        expected_server_profile_built["connectionSettings"][
            "connections"].append(self.fc_connection)

        self.run_common_mock_to_server_hardware()
        self.run_common_mock_to_server_profile_template()
        self.run_common_mock_to_drives()
        self.run_common_mock_to_volumes()
        storage_pool_obj = StoragePools(
            self.oneview_client,
            {"storageSystemUri": "/rest/storage-systems/TXQ1000307"})
        self.oneview_client.storage_pools.get_by_uri.return_value = storage_pool_obj
        config_mock.get_composition_settings.return_value = {
            'PowerOffServerOnCompose': ''
        }

        task_with_resource_uri = {
            "associatedResource": {
                "resourceUri": self.server_profile["uri"]
            },
            "uri": "/rest/tasks/123456"
        }

        self.oneview_client.connection.post.return_value = \
            (task_with_resource_uri, None)

        response = self.client.post("/redfish/v1/Systems",
                                    data=json.dumps(
                                        self.data_to_create_system),
                                    content_type="application/json")

        self.assertEqual(status.HTTP_201_CREATED, response.status_code)
        self.assertEqual("application/json", response.mimetype)

        power_state.update_power_state \
            .assert_not_called()
    def test_get_external_storage_volumes(self):
        """Tests get external storage volume for computer system"""

        with open('oneview_redfish_toolkit/mockups/redfish/'
                  'VolumesResourceBlock.json') as f:
            expected_storage_details = json.load(f)

        with open('oneview_redfish_toolkit/mockups/oneview/Volumes.json') as f:
            volume = json.load(f)

        expected_storage_details["@odata.id"] = "/redfish/v1/Systems/" + \
            "b425802b-a6a5-4941-8885-aab68dfa2ee2/Storage/1/Volumes/" + \
            "B526F59E-9BC7-467F-9205-A9F4015CE296"
        expected_storage_details["Id"] = \
            "B526F59E-9BC7-467F-9205-A9F4015CE296"

        storage_pool_obj = StoragePools(
            self.oneview_client, {
                "uri":
                "/rest/storage-pools/DC8BD64B-9A4E-4722-92D3-A9F4015B0B71",
                "deviceSpecificAttributes": {
                    "supportedRAIDLevel": "RAID6"
                }
            })

        self.oneview_client.storage_pools.get_by_uri.return_value = storage_pool_obj
        server_profile = copy.deepcopy(self.server_profile)
        server_profile["sanStorage"] = self.san_storage

        profile_obj = ServerProfiles(self.oneview_client, server_profile)
        self.oneview_client.server_profiles.get_by_id.return_value = profile_obj
        volume_obj = Volumes(self.oneview_client, volume[0])
        self.oneview_client.volumes.get_by_id.return_value = volume_obj

        response = self.client.get(
            "/redfish/v1/Systems/"
            "b425802b-a6a5-4941-8885-aab68dfa2ee2/Storage/1/Volumes/"
            "B526F59E-9BC7-467F-9205-A9F4015CE296")

        result = json.loads(response.data.decode("utf-8"))
        print(result)
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(expected_storage_details, result)
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._storage_pools = StoragePools(self.connection)
class StoragePoolsTest(unittest.TestCase):

    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._storage_pools = StoragePools(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._storage_pools.get_all(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once_with_default(self, mock_get_all):
        self._storage_pools.get_all()
        mock_get_all.assert_called_once_with(0, -1, filter='', sort='')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        storage_pools_id = "EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_id)
        mock_get.assert_called_once_with(storage_pools_id)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        storage_pools_uri = "/rest/storage-pools/EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_uri)
        mock_get.assert_called_once_with(storage_pools_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once_with_defaults(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool)
        mock_create.assert_called_once_with(storage_pool, timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool, 70)
        mock_create.assert_called_once_with(storage_pool, timeout=70)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id, force=True, timeout=50)

        mock_delete.assert_called_once_with(id, force=True, timeout=50)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once_with_defaults(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id)

        mock_delete.assert_called_once_with(id, force=False, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._storage_pools.get_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")
Exemple #8
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._storage_pools = StoragePools(self.connection)
Exemple #9
0
class StoragePoolsTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._storage_pools = StoragePools(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._storage_pools.get_all(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once_with_default(self, mock_get_all):
        self._storage_pools.get_all()
        mock_get_all.assert_called_once_with(0, -1, filter='', sort='')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        storage_pools_id = "EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_id)
        mock_get.assert_called_once_with(storage_pools_id)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        storage_pools_uri = "/rest/storage-pools/EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_uri)
        mock_get.assert_called_once_with(storage_pools_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once_with_defaults(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool)
        mock_create.assert_called_once_with(storage_pool, timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool, 70)
        mock_create.assert_called_once_with(storage_pool, timeout=70)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id, force=True, timeout=50)

        mock_delete.assert_called_once_with(id, force=True, timeout=50)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once_with_defaults(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id)

        mock_delete.assert_called_once_with(id, force=False, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._storage_pools.get_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")
    def test_create_system_when_has_not_storage_and_controller(
            self, _, power_state):
        """Tests create a System without Storage but with Storage Controller.

            This test should works well.

            This case is when we are creating a System without Storage
            Resource Blocks and the Server Profile Template related has not a
            local storage controller configured properly
        """

        task = {
            "associatedResource": {
                "resourceUri": self.server_profile["uri"]
            },
            "uri": "/rest/tasks/123456"
        }
        serverhw_obj = ServerHardware(self.oneview_client,
                                      self.server_hardware)
        self.oneview_client.server_hardware.get_by_id.side_effect = [
            serverhw_obj,
            self.not_found_error,
            self.not_found_error,
            self.not_found_error,
            self.not_found_error,
            serverhw_obj,  # for multiple oneview (power update status)
            serverhw_obj  # Get for multiple OneView support
        ]
        power_state.return_value = None

        template_without_controller = copy.deepcopy(
            self.server_profile_template)
        template_without_controller["localStorage"]["controllers"] = []
        template_obj = ServerProfileTemplate(self.oneview_client,
                                             template_without_controller)
        self.oneview_client.server_profile_templates.get_by_id.side_effect = [
            self.not_found_error, template_obj, self.not_found_error,
            self.not_found_error, self.not_found_error, template_obj
        ]
        self.oneview_client.index_resources.get.side_effect = [
            self.not_found_error,
            self.not_found_error,
            self.not_found_error,
            self.not_found_error,
            self.not_found_error,
        ]

        self.run_common_mock_to_volumes()
        storage_pools_obj = StoragePools(
            self.oneview_client,
            {"storageSystemUri": "/rest/storage-systems/TXQ1000307"})
        self.oneview_client.storage_pools.get.return_value = storage_pools_obj

        self.oneview_client.connection.post.return_value = (task, None)

        response = self.client.post("/redfish/v1/Systems/",
                                    data=json.dumps(
                                        self.data_to_create_system),
                                    content_type='application/json')

        self.assertEqual(status.HTTP_201_CREATED, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        # self.assertIn(
        #     "/redfish/v1/Systems/" + self.server_profile["uuid"],
        #     response.headers["Location"]
        # )
        self.assert_common_calls()
    def test_create_system_without_description(self, time_mock, power_state):
        """Tests create a redfish System with Network, Storage and Server"""

        with open('oneview_redfish_toolkit/mockups/oneview/'
                  'ServerProfileBuiltFromTemplateToCreateASystem.json') as f:
            expected_server_profile_built = json.load(f)

        task_without_resource_uri = {
            "associatedResource": {
                "resourceUri": None
            },
            "uri": "/rest/tasks/123456"
        }

        task_with_resource_uri = {
            "associatedResource": {
                "resourceUri": self.server_profile["uri"]
            },
            "uri": "/rest/tasks/123456"
        }

        expected_server_profile_built["sanStorage"] = self.san_storage

        expected_server_profile_built["connectionSettings"][
            "connections"].append(self.fc_connection)

        data_to_create_without_desc = copy.deepcopy(self.data_to_create_system)
        del expected_server_profile_built['description']
        data_to_create_without_desc['Description'] = ''

        self.run_common_mock_to_server_hardware()
        power_state.return_value = None
        self.run_common_mock_to_server_profile_template()
        self.run_common_mock_to_drives()
        self.run_common_mock_to_volumes()
        storage_prool_obj = StoragePools(
            self.oneview_client,
            {"storageSystemUri": "/rest/storage-systems/TXQ1000307"})
        self.oneview_client.storage_pools.get.return_value = storage_prool_obj

        # The connection.post return for /rest/server-profiles is a tuple
        self.oneview_client.connection.post.return_value = \
            (task_without_resource_uri, None)

        # The task will be requested 3 times in this case,
        # simulating the checking of resource uri
        task_without_resource_uri_obj = Tasks(self.oneview_client,
                                              task_without_resource_uri)
        task_with_resource_uri_obj = Tasks(self.oneview_client,
                                           task_with_resource_uri)
        self.oneview_client.tasks.get_by_uri.side_effect = [
            task_without_resource_uri_obj, task_without_resource_uri_obj,
            task_with_resource_uri_obj
        ]

        response = self.client.post(
            "/redfish/v1/Systems",
            data=json.dumps(data_to_create_without_desc),
            content_type='application/json')

        self.assertEqual(status.HTTP_201_CREATED, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertIn("/redfish/v1/Systems/" + self.server_profile["uuid"],
                      response.headers["Location"])

        self.oneview_client.server_hardware.get_by_id.assert_has_calls(
            self.common_calls_to_assert_hardware)
        self.oneview_client.server_profile_templates.get_by_id.assert_has_calls(
            self.common_calls_to_assert_spt)
        self.oneview_client.index_resources.get.assert_has_calls(
            self.common_calls_to_assert_drives)
        self.oneview_client.server_profiles.create.assert_not_called()

        self.oneview_client.tasks.get_by_uri.assert_called_with(
            task_without_resource_uri["uri"])
        # self.oneview_client.connection.post.assert_called_once_with(
        #     '/rest/server-profiles', expected_server_profile_built
        # )
        self.assertEqual(self.oneview_client.tasks.get_by_uri.call_count, 3)
        time_mock.sleep.assert_called_with(3)
 def storage_pools(self):
     if not self.__storage_pools:
         self.__storage_pools = StoragePools(self.__connection)
     return self.__storage_pools
class StoragePoolsTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._storage_pools = StoragePools(self.connection)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._storage_pools.get_all(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort)

    @mock.patch.object(ResourceClient, 'get_all')
    def test_get_all_called_once_with_default(self, mock_get_all):
        self._storage_pools.get_all()
        mock_get_all.assert_called_once_with(0, -1, filter='', sort='')

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        storage_pools_id = "EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_id)
        mock_get.assert_called_once_with(storage_pools_id)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        storage_pools_uri = "/rest/storage-pools/EE9326ED-4595-4828-B411-FE3BD6BA7E9D"
        self._storage_pools.get(storage_pools_uri)
        mock_get.assert_called_once_with(storage_pools_uri)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once_with_defaults(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool)
        mock_create.assert_called_once_with(storage_pool, timeout=-1)

    @mock.patch.object(ResourceClient, 'create')
    def test_add_called_once(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool, 70)
        mock_create.assert_called_once_with(storage_pool, timeout=70)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id, force=True, timeout=50)

        mock_delete.assert_called_once_with(id, force=True, timeout=50)

    @mock.patch.object(ResourceClient, 'delete')
    def test_remove_called_once_with_defaults(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.remove(id)

        mock_delete.assert_called_once_with(id, force=False, timeout=-1)

    @mock.patch.object(ResourceClient, 'get_by')
    def test_get_by_called_once(self, mock_get_by):
        self._storage_pools.get_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, mock_update):
        storage_pool = {
            "name": "SSD",
            "uri": "rest/fake/pool",
            "raidLevel": "RAID5"
        }
        self._storage_pools.update(storage_pool, 70)
        mock_update.assert_called_once_with(storage_pool, timeout=70)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_reachable_storage_pools_called_once(self, mock_get):
        query_params = "networks='/rest/networks/fake'&scopeExclusions=/rest/scope/fake"
        uri = "/rest/storage-pools/reachable-storage-pools?" + query_params + "&start=0&count=-1"
        self._storage_pools.get_reachable_storage_pools(
            networks=['/rest/networks/fake'],
            scope_exclusions=['/rest/scope/fake'])
        mock_get.assert_called_once_with(uri)
Exemple #14
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._storage_pools = StoragePools(self.connection)
     self.uri = '/rest/storage-pools/ad28cf21-8b15-4f92-bdcf-51cb2042db32'
     self._storage_pools.data = {'uri': self.uri}
Exemple #15
0
class StoragePoolsTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._storage_pools = StoragePools(self.connection)
        self.uri = '/rest/storage-pools/ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._storage_pools.data = {'uri': self.uri}

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_all_called_once(self, mock_get_all):
        filter = 'name=TestName'
        sort = 'name:ascending'

        self._storage_pools.get_all(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(count=500,
                                             filter='name=TestName',
                                             sort='name:ascending',
                                             start=2)

    @mock.patch.object(ResourceHelper, 'get_all')
    def test_get_all_called_once_with_default(self, mock_get_all):
        self._storage_pools.get_all()
        mock_get_all.assert_called_once_with(count=-1,
                                             filter='',
                                             sort='',
                                             start=0)

    @mock.patch.object(ResourceHelper, 'create')
    def test_add_called_once_with_defaults(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool)
        mock_create.assert_called_once_with(storage_pool, None, -1, None,
                                            False)

    @mock.patch.object(ResourceHelper, 'create')
    def test_add_called_once(self, mock_create):
        storage_pool = {
            "storageSystemUri": "/rest/storage-systems/111111",
            "poolName": "storagepool1"
        }
        self._storage_pools.add(storage_pool, 70)
        mock_create.assert_called_once_with(storage_pool, None, 70, None,
                                            False)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_remove_called_once(self, mock_delete):
        self._storage_pools.remove(force=True, timeout=50)

        mock_delete.assert_called_once_with(
            '/rest/storage-pools/ad28cf21-8b15-4f92-bdcf-51cb2042db32',
            custom_headers=None,
            force=True,
            timeout=50)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_remove_called_once_with_defaults(self, mock_delete):
        self._storage_pools.remove()

        mock_delete.assert_called_once_with(
            '/rest/storage-pools/ad28cf21-8b15-4f92-bdcf-51cb2042db32',
            custom_headers=None,
            force=False,
            timeout=-1)

    @mock.patch.object(ResourceHelper, 'update')
    @mock.patch.object(ResourceHelper, 'do_get')
    def test_update_called_once(self, mock_get, mock_update):
        storage_pool = {"name": "SSD", "raidLevel": "RAID5", "uri": self.uri}
        mock_get.return_value = storage_pool

        self._storage_pools.update(storage_pool, 70)
        mock_update.assert_called_once_with(storage_pool, self.uri, False, 70,
                                            None)

    @mock.patch.object(ResourceHelper, 'do_get')
    def test_get_reachable_storage_pools_called_once(self, mock_get):
        query_params = "networks='/rest/networks/fake'&scopeExclusions=/rest/scope/fake"
        uri = "/rest/storage-pools/reachable-storage-pools?" + query_params + "&start=0&count=-1"
        self._storage_pools.get_reachable_storage_pools(
            networks=['/rest/networks/fake'],
            scope_exclusions=['/rest/scope/fake'])
        mock_get.assert_called_once_with(uri)