def test_composed_system_without_drives(self):
        """Tests Storage when it does not have drives"""
        server_profile = copy.deepcopy(self.server_profile)
        server_profile["localStorage"]["sasLogicalJBODs"] = []
        storage_mockup_without_drives = copy.deepcopy(self.storage_mockup)
        storage_mockup_without_drives["Drives"] = []
        storage_mockup_without_drives["*****@*****.**"] = 0
        del storage_mockup_without_drives["Volumes"]
        profile_obj = ServerProfiles(self.oneview_client, server_profile)
        self.oneview_client.server_profiles.get_by_id.return_value = profile_obj
        server_hardware_type_obj = ServerHardwareTypes(
            self.oneview_client, self.server_hardware_type)
        self.oneview_client.server_hardware_types.get_by_uri.return_value \
            = server_hardware_type_obj

        response = self.client.get(
            "/redfish/v1/Systems/"
            "b425802b-a6a5-4941-8885-aab68dfa2ee2/Storage/1")

        # Gets json from response
        result = json.loads(response.data.decode("utf-8"))

        # Tests response
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(storage_mockup_without_drives, result)
        self.oneview_client.server_profiles.get_by_id.assert_called_with(
            self.server_profile["uuid"])
        self.oneview_client.server_hardware_types.get_by_uri.assert_called_with(
            self.server_hardware_type["uri"])
        self.oneview_client.sas_logical_jbods.get.assert_not_called()
    def test_get_storage(self):
        """Tests Storage"""
        server_hardware_type_obj = ServerHardwareTypes(
            self.oneview_client, self.server_hardware_type)
        profile_obj = ServerProfiles(self.oneview_client, self.server_profile)

        self.oneview_client.\
            server_profiles.get_by_id.return_value = profile_obj
        self.oneview_client.server_hardware_types.get_by_uri.return_value \
            = server_hardware_type_obj
        self.oneview_client.\
            sas_logical_jbods.get.side_effect = self.logical_jbods

        response = self.client.get(
            "/redfish/v1/Systems/"
            "b425802b-a6a5-4941-8885-aab68dfa2ee2/Storage/1")

        # Gets json from response
        result = json.loads(response.data.decode("utf-8"))

        # Tests response
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(self.storage_mockup, result)
        self.oneview_client.server_profiles.get_by_id.assert_called_with(
            self.server_profile["uuid"])
        self.oneview_client.server_hardware_types.get_by_uri.assert_called_with(
            self.server_hardware_type["uri"])
        self.oneview_client.sas_logical_jbods.get.assert_has_calls([
            call(self.logical_jbods[0]["uri"]),
            call(self.logical_jbods[1]["uri"])
        ])
    def server_hardware_types(self):
        """
        Gets the ServerHardwareTypes API client.

        Returns:
            ServerHardwareTypes:
        """
        return ServerHardwareTypes(self.__connection)
Exemplo n.º 4
0
    def test_all_computer_system_states(self, get_map_appliances,
                                        get_map_resources):
        expected_cs = copy.deepcopy(self.computer_system_mockup)
        server_profile = copy.deepcopy(self.server_profile)
        server_profile["localStorage"]["sasLogicalJBODs"].pop(0)

        for oneview_status, redfish_status in status_mapping.\
                SERVER_PROFILE_STATE_TO_REDFISH_STATE.items():

            server_profile["state"] = oneview_status
            expected_cs["Status"]["State"] = redfish_status

            resource_id = "/rest/server-hardware-types/" \
                          "FE50A6FE-B1AC-4E42-8D40-B73CA8CC0CD2"
            get_map_resources.return_value = OrderedDict({
                resource_id:
                "10.0.0.1",
            })
            get_map_appliances.return_value = self.map_appliance
            profile_obj = ServerProfiles(self.oneview_client, server_profile)
            serverhw_obj = ServerHardware(self.oneview_client,
                                          self.server_hardware)
            server_hardware_type_obj = ServerHardwareTypes(
                self.oneview_client, self.server_hardware_types)
            self.oneview_client.server_profiles.get_by_id.return_value = \
                profile_obj
            self.oneview_client.server_hardware.get_by_uri.return_value = \
                serverhw_obj
            self.oneview_client.server_hardware_types.get_by_uri.return_value = \
                server_hardware_type_obj
            self.oneview_client.sas_logical_jbods.get_drives.return_value = \
                [self.drives[4]]
            self.oneview_client.labels.get_by_resource.return_value = \
                self.label_for_server_profile
            self.oneview_client.appliance_node_information.get_version.return_value = \
                self.appliance_info

            response = self.client.get(
                "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2")

            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_cs, result)
Exemplo n.º 5
0
    def test_get_computer_system_sp_with_invalid_labels(
            self, get_map_appliances, get_map_resources):
        """Tests ComputerSystem with a known SP with invalid labels"""

        server_profile = copy.deepcopy(self.server_profile)
        server_profile["localStorage"]["sasLogicalJBODs"].pop(0)
        invalid_label = {
            "uri": "/rest/labels/2",
            "name": "invalid label abc123"
        }

        label_for_sp = copy.deepcopy(self.label_for_server_profile)
        label_for_sp["labels"].extend(invalid_label)

        server_profile_template = copy.deepcopy(self.server_profile_template)
        server_profile_template["uri"] = self.spt_uri

        # Create mock response
        resource_id = "/rest/server-hardware-types/" \
                      "FE50A6FE-B1AC-4E42-8D40-B73CA8CC0CD2"
        get_map_resources.return_value = OrderedDict({
            resource_id: "10.0.0.1",
        })
        get_map_appliances.return_value = self.map_appliance
        profile_obj = ServerProfiles(self.oneview_client, server_profile)
        serverhw_obj = ServerHardware(self.oneview_client,
                                      self.server_hardware)
        template_obj = ServerProfileTemplate(self.oneview_client,
                                             server_profile_template)
        server_hardware_type_obj = ServerHardwareTypes(
            self.oneview_client, self.server_hardware_types)
        self.oneview_client.server_profiles.get_by_id.return_value = profile_obj
        self.oneview_client.server_hardware.get_by_uri.return_value = \
            serverhw_obj
        self.oneview_client.server_hardware_types.get_by_uri.return_value = \
            server_hardware_type_obj
        self.oneview_client.sas_logical_jbods.get_drives.return_value = \
            [self.drives[4]]
        self.oneview_client.labels.get_by_resource.return_value = label_for_sp
        self.oneview_client.server_profile_templates.get_by_id.return_value = \
            template_obj
        self.oneview_client.appliance_node_information.get_version.return_value = \
            self.appliance_info

        # Get ComputerSystem
        response = self.client.get(
            "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2")

        # Gets json from response
        result = json.loads(response.data.decode("utf-8"))

        # Tests response
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(self.computer_system_mockup, result)
        self.assertEqual("{}{}".format("W/", self.server_profile["eTag"]),
                         response.headers["ETag"])
        self.oneview_client.server_profiles.get_by_id.assert_called_with(
            "b425802b-a6a5-4941-8885-aab68dfa2ee2")
        self.oneview_client.server_hardware.get_by_uri.assert_called_with(
            "/rest/server-hardware/30303437-3034-4D32-3230-313130304752")
        self.oneview_client.server_hardware_types.get_by_uri.assert_called_with(
            "/rest/server-hardware-types/FE50A6FE-B1AC-4E42-8D40-B73CA8CC0CD2")
        self.oneview_client.sas_logical_jbods.get_drives.assert_called_with(
            "/rest/sas-logical-jbods/9e83a03d-7a84-4f0d-a8d7-bd05a30c3175")

        self.oneview_client.labels.get_by_resource.assert_called_with(
            "/rest/server-profiles/b425802b-a6a5-4941-8885-aab68dfa2ee2")

        self.oneview_client.server_profile_templates.get_by_id.assert_called_with(
            "61c3a463-1355-4c68-a4e3-4f08c322af1b")
Exemplo n.º 6
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._server_hardware_types = ServerHardwareTypes(self.connection)
Exemplo n.º 7
0
class ServerHardwareTypesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._server_hardware_types = ServerHardwareTypes(self.connection)

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

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

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

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        server_hardware_type_id = "f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
        self._server_hardware_types.get(server_hardware_type_id)
        mock_get.assert_called_once_with(server_hardware_type_id)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        server_hardware_type_uri = "/rest/server-hardware-types/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
        self._server_hardware_types.get(server_hardware_type_uri)
        mock_get.assert_called_once_with(server_hardware_type_uri)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_defaults(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type)
        update.assert_called_once_with(server_hardware_type, None, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type, None, 70)
        update.assert_called_once_with(server_hardware_type, None, timeout=70)

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

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

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_called_once_with_defaults(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._server_hardware_types.delete(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._server_hardware_types.get_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")
Exemplo n.º 8
0
 def server_hardware_types(self):
     if not self.__server_hardware_types:
         self.__server_hardware_types = ServerHardwareTypes(
             self.__connection)
     return self.__server_hardware_types
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._server_hardware_types = ServerHardwareTypes(self.connection)
class ServerHardwareTypesTest(unittest.TestCase):

    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._server_hardware_types = ServerHardwareTypes(self.connection)

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

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

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

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_id_called_once(self, mock_get):
        server_hardware_type_id = "f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
        self._server_hardware_types.get(server_hardware_type_id)
        mock_get.assert_called_once_with(server_hardware_type_id)

    @mock.patch.object(ResourceClient, 'get')
    def test_get_by_uri_called_once(self, mock_get):
        server_hardware_type_uri = "/rest/server-hardware-types/f0a0a113-ec97-41b4-83ce-d7c92b900e7c"
        self._server_hardware_types.get(server_hardware_type_uri)
        mock_get.assert_called_once_with(server_hardware_type_uri)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once_with_defaults(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type)
        update.assert_called_once_with(
            server_hardware_type, None, timeout=-1)

    @mock.patch.object(ResourceClient, 'update')
    def test_update_called_once(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type, None, 70)
        update.assert_called_once_with(
            server_hardware_type, None, timeout=70)

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

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

    @mock.patch.object(ResourceClient, 'delete')
    def test_delete_called_once_with_defaults(self, mock_delete):
        id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32'
        self._server_hardware_types.delete(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._server_hardware_types.get_by("name", "test name")

        mock_get_by.assert_called_once_with("name", "test name")
Exemplo n.º 11
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._server_hardware_types = ServerHardwareTypes(self.connection)
     self.uri = "/rest/server-hardware-types/ad28cf21-8b15-4f92-bdcf-51cb2042db32"
     self._server_hardware_types.data = {'uri': self.uri}
Exemplo n.º 12
0
class ServerHardwareTypesTest(unittest.TestCase):
    def setUp(self):
        self.host = '127.0.0.1'
        self.connection = connection(self.host)
        self._server_hardware_types = ServerHardwareTypes(self.connection)
        self.uri = "/rest/server-hardware-types/ad28cf21-8b15-4f92-bdcf-51cb2042db32"
        self._server_hardware_types.data = {'uri': self.uri}

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

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

        self._server_hardware_types.get_all(2, 500, filter, sort)
        mock_get_all.assert_called_once_with(start=2,
                                             count=500,
                                             filter=filter,
                                             sort=sort)

    @mock.patch.object(ResourceHelper, 'update')
    def test_update_called_once_with_defaults(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type)
        update.assert_called_once_with(server_hardware_type,
                                       force=False,
                                       timeout=-1,
                                       uri=self.uri)

    @mock.patch.object(ResourceHelper, 'update')
    def test_update_called_once(self, update):
        server_hardware_type = {
            "name": "New Server Type Name",
            "description": "New Description"
        }
        self._server_hardware_types.update(server_hardware_type, timeout=70)
        update.assert_called_once_with(server_hardware_type,
                                       force=False,
                                       timeout=70,
                                       uri=self.uri)

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

        mock_delete.assert_called_once_with(self.uri,
                                            force=True,
                                            timeout=50,
                                            custom_headers=None)

    @mock.patch.object(ResourceHelper, 'delete')
    def test_delete_called_once_with_defaults(self, mock_delete):
        self._server_hardware_types.delete()

        mock_delete.assert_called_once_with(self.uri,
                                            force=False,
                                            timeout=-1,
                                            custom_headers=None)

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

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