コード例 #1
0
    def test_get_enclosure_env_config_not_found(self, get_map_appliances,
                                                get_map_resources,
                                                config_mock, get_env):
        """Tests EnclosureChassis with Enclosure env_config not found"""

        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)


        config_mock.get_oneview_multiple_ips.return_value = ['10.0.0.1']


        get_map_resources.return_value = OrderedDict({
            "0000000000A66101": "10.0.0.1",
        })
        get_map_appliances.return_value = self.map_appliance
        self.oneview_client.index_resources.get_all.return_value = \
            [{"category": "enclosures"}]

        self.oneview_client.enclosures.get_by_id.return_value = enclosure_obj

        e = HPOneViewException({
            'errorCode': 'RESOURCE_NOT_FOUND',
            'message': 'environmental configuration not found',
        })
        Enclosures.get_environmental_configuration. \
            side_effect = e

        response = self.client.get(
            "/redfish/v1/Chassis/0000000000A66101"
        )

        self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
        self.assertEqual("application/json", response.mimetype)
コード例 #2
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._enclosures = Enclosures(self.connection)
     self._enclosures.data = {
         'uri': '/rest/enclosures/ad28cf21-8b15-4f92-bdcf-51cb2042db32'
     }
コード例 #3
0
    def test_get_enclosure_chassis(self, get_map_appliances,
                                   get_map_resources,get_env):
        """"Tests EnclosureChassis with a known Enclosure"""
        get_env.return_value = self.enclosure_environment_configuration_mockup
        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        get_map_resources.return_value = OrderedDict({
            "0000000000A66101": "10.0.0.1",
        })
        get_map_appliances.return_value = self.map_appliance
        self.oneview_client.index_resources.get_all.return_value = \
            [{"category": "enclosures"}]
        self.oneview_client.enclosures.get_by_id.return_value = enclosure_obj
        Enclosures.get_environmental_configuration.return_value = \
            get_env.return_value
        self.oneview_client.appliance_node_information.get_version.return_value = \
            self.appliance_info

        # Get EnclosureChassis
        response = self.client.get(
            "/redfish/v1/Chassis/0000000000A66101"
        )

        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.enclosure_chassis_mockup, result)
        self.assertEqual(
            "{}{}".format("W/", self.enclosure["eTag"]),
            response.headers["ETag"])
コード例 #4
0
    def test_get_zone_when_external_storage_attached(self):
        """Tests get a Zone when the zone uuid is only template id"""

        api_client = self.oneview_client

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

        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        api_client.enclosures.get_by_id.return_value = enclosure_obj

        spt_obj = ServerProfileTemplate(self.oneview_client,
                                        self.server_profile_template)
        api_client.server_profile_templates.get_by_id.return_value = \
            spt_obj

        api_client.server_hardware.get_all.return_value = \
            self.server_hardware_list
        api_client.connection.get.side_effect = [
            self.drive_encl_assoc, self.drives
        ]
        api_client.volumes.get_all.return_value = \
            self.volumes
        response = self.client.get(
            "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id +
            "-" + self.enclosure["uuid"])

        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(zone_with_external_storage_mockup, result)
コード例 #5
0
    def enclosures(self):
        """
        Gets the Enclosures API client.

        Returns:
            Enclosures:
        """
        return Enclosures(self.__connection)
コード例 #6
0
    def test_get_zone_when_uuid_is_template_id_with_enclosure_id(self):
        """Tests get a Zone when the zone uuid is template id + enclosure id"""

        api_client = self.oneview_client

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

        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        api_client.enclosures.get_by_id.return_value = enclosure_obj

        spt_obj = ServerProfileTemplate(
            self.oneview_client, self.server_profile_template)
        api_client.server_profile_templates.get_by_id.return_value = \
            spt_obj

        api_client.server_hardware.get_all.return_value = \
            self.server_hardware_list
        api_client.connection.get.side_effect = [
            self.drive_encl_assoc,
            self.drives
        ]
        api_client.volumes.get_all.return_value = []

        response = self.client.get(
            "/redfish/v1/CompositionService/ResourceZones/" +
            self.spt_id + "-" + self.enclosure["uuid"])

        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(zone_mockup, result)

        api_client.enclosures.get_by_id.assert_called_with(
            self.enclosure["uuid"])
        api_client.server_profile_templates.get_by_id.assert_called_with(
            self.spt_id)
        api_client.connection.get.assert_has_calls(
            [
                call("/rest/index/associations/resources?parenturi=" +
                     self.enclosure["uri"] + "&category=drive-enclosures"),
                call('/rest/index/resources?category=drives&count=10000'
                     '&filter="driveEnclosureUri:'
                     '/rest/drive-enclosures/SN123100"')
            ]
        )
        api_client.server_hardware.get_all.assert_called_with(
            filter=[
                "locationUri='/rest/enclosures/0000000000A66101'",

                "serverHardwareTypeUri='"
                + self.server_profile_template["serverHardwareTypeUri"] + "'"
            ])
コード例 #7
0
    def test_get_zone_when_drive_enclosures_assoc_is_empty(self):
        """Tests get a Zone when drive enclosures by enclosure is empty"""

        api_client = self.oneview_client

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

        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        api_client.enclosures.get_by_id.return_value = enclosure_obj

        spt_obj = ServerProfileTemplate(
            self.oneview_client, self.server_profile_template)
        api_client.server_profile_templates.get_by_id.return_value = \
            spt_obj

        drive_encl_by_encl = copy.copy(self.drive_encl_assoc)
        drive_encl_by_encl["members"] = []
        api_client.connection.get.side_effect = [
            drive_encl_by_encl,
            self.drives
        ]
        api_client.server_hardware.get_all.return_value = \
            self.server_hardware_list

        api_client.volumes.get_all.return_value = []

        response = self.client.get(
            "/redfish/v1/CompositionService/ResourceZones/" +
            self.spt_id + "-" + self.enclosure["uuid"])

        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(zone_without_drives_mockup, result)

        api_client.enclosures.get_by_id.assert_called_with(
            self.enclosure["uuid"])
        api_client.server_profile_templates.get_by_id.assert_called_with(
            self.spt_id)
        api_client.connection.get.assert_has_calls([
            call("/rest/index/associations/resources?parenturi="
                 + self.enclosure["uri"]
                 + "&category=drive-enclosures")
        ])
        api_client.server_hardware.get_all.assert_called_with(
            filter=[
                "locationUri='/rest/enclosures/0000000000A66101'",

                "serverHardwareTypeUri='"
                + self.server_profile_template["serverHardwareTypeUri"] + "'"
            ])
コード例 #8
0
    def enclosures(self):
        """
        Gets the Enclosures API client.

        Returns:
            Enclosures:
        """
        if not self.__enclosures:
            self.__enclosures = Enclosures(self.__connection)
        return self.__enclosures
コード例 #9
0
    def test_get_enclosure_chassis_cached(self, get_map_appliances,
                                          get_map_resources, get_env):
        """"Tests EnclosureChassis with a known Enclosure"""
        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        get_env.return_value = self.enclosure_environment_configuration_mockup

        get_map_resources.return_value = OrderedDict({
            "0000000000A66101": "10.0.0.1",
        })
        get_map_appliances.return_value = self.map_appliance
        self.oneview_client.index_resources.get_all.return_value = \
            [{"category": "enclosures"}]
        self.oneview_client.enclosures.get_by_id.return_value = enclosure_obj
        Enclosures.get_environmental_configuration. \
            return_value = get_env.return_value
        self.oneview_client.appliance_node_information.get_version.return_value = \
            self.appliance_info

        uri = "/redfish/v1/Chassis/0000000000A66101"
        uuid = uri.split('/')[-1]

        # Get EnclosureChassis
        response = self.client.get(uri)

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

        # Tests response
        self.assertEqual(status.HTTP_200_OK, response.status_code)

        # Get cached EnclosureChassis
        response = self.client.get(uri)

        # Tests cached response
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual("application/json", response.mimetype)
        self.assertEqualMockup(self.enclosure_chassis_mockup, result)
        self.assertEqual(
            "{}{}".format("W/", self.enclosure["eTag"]),
            response.headers["ETag"])

        # Check for cached calls
        self.oneview_client.index_resources.get_all.assert_called_once_with(
            filter='uuid=' + uuid
        )
        assert self.oneview_client.enclosures.get.has_calls(
            [call(uuid),
             call(uuid)]
        )
        self.assertTrue(category_resource.get_category_by_resource_id(uuid))
コード例 #10
0
    def test_enclosure_env_config_unexpected_error(self):
        """Tests EnclosureChassis env_config with an unexpected error"""

        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)

        self.oneview_client.index_resources.get_all.return_value = \
            [{"category": "enclosures"}]

        self.oneview_client.enclosures.get_by_id.return_value = enclosure_obj
        Enclosures.get_environmental_configuration. \
            side_effect = Exception()

        response = self.client.get("/redfish/v1/Chassis/0000000000A66101")

        self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR,
                         response.status_code)
        self.assertEqual("application/json", response.mimetype)
コード例 #11
0
    def test_get_enclosure_chassis_when_enclosure_does_not_belong_to_rack(
            self,
            get_map_appliances,
            get_map_resources, get_env):
        """"Tests EnclosureChassis when a Enclosure doesn't belong to a Rack"""

        encl_env_config_mockup = copy.deepcopy(
            self.enclosure_environment_configuration_mockup)
        encl_env_config_mockup['rackId'] = None

        encl_mockup = copy.deepcopy(self.enclosure_chassis_mockup)
        del encl_mockup['Links']['ContainedBy']
        enclosure_obj = Enclosures(self.oneview_client, self.enclosure)
        get_map_resources.return_value = OrderedDict({
            "0000000000A66101": "10.0.0.1",
        })
        get_env.return_value = encl_env_config_mockup
        get_map_appliances.return_value = self.map_appliance
        self.oneview_client.index_resources.get_all.return_value = \
            [{"category": "enclosures"}]
        self.oneview_client.enclosures.get_by_id.return_value = enclosure_obj
        Enclosures.get_environmental_configuration. \
            return_value = get_env.return_value
        self.oneview_client.appliance_node_information.get_version.return_value = \
            self.appliance_info

        # Get EnclosureChassis
        response = self.client.get(
            "/redfish/v1/Chassis/0000000000A66101"
        )

        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(encl_mockup, result)
        self.assertEqual(
            "{}{}".format("W/", self.enclosure["eTag"]),
            response.headers["ETag"])
コード例 #12
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.connection = connection(self.host)
     self._enclosures = Enclosures(self.connection)
コード例 #13
0
 def enclosures(self):
     if not self.__enclosures:
         self.__enclosures = Enclosures(self.__connection)
     return self.__enclosures