Example #1
0
    def test_set_boot_device(self, mock_ccj, mock_cfcj, mock_client_pywsman):
        result_xml_enum = test_utils.build_soap_xml([{'InstanceID': 'NIC'}],
                                      resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml([{'ReturnValue':
                                                     drac_common.RET_SUCCESS}],
                                      resource_uris.DCIM_BootConfigSetting)

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            task.node = self.node
            result = self.driver.set_boot_device(task, boot_devices.PXE)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_BootConfigSetting,
            'ChangeBootOrderByInstanceID')
        mock_cfcj.assert_called_once_with(self.node)
        mock_ccj.assert_called_once_with(self.node)
Example #2
0
    def test_set_boot_device_fail(self, mock_ccj, mock_cfcj,
                                  mock_client_pywsman):
        result_xml_enum = test_utils.build_soap_xml([{'InstanceID': 'NIC'}],
                                      resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_ERROR, 'Message': 'E_FAKE'}],
            resource_uris.DCIM_BootConfigSetting)

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk
        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            task.node = self.node
            self.assertRaises(exception.DracOperationFailed,
                              self.driver.set_boot_device, task,
                              boot_devices.PXE)

        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_BootConfigSetting,
            'ChangeBootOrderByInstanceID',
            None)
        mock_cfcj.assert_called_once_with(self.node)
        self.assertFalse(mock_ccj.called)
Example #3
0
    def test_wsman_enumerate_with_additional_pull(self, mock_client_pywsman):
        mock_root = mock.Mock(spec=['string'])
        mock_root.string.side_effect = [
            test_utils.build_soap_xml([{'item1': 'test1'}]),
            test_utils.build_soap_xml([{'item2': 'test2'}])
        ]
        mock_xml = mock.Mock(spec=['context', 'root'])
        mock_xml.root.return_value = mock_root
        mock_xml.context.side_effect = [42, 42, None]

        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.enumerate.return_value = mock_xml
        mock_pywsman_client.pull.return_value = mock_xml

        client = drac_client.Client(**INFO_DICT)
        result = client.wsman_enumerate(self.resource_uri)

        # assert the XML was merged
        result_string = ElementTree.tostring(result)
        self.assertIn(b'<item1>test1</item1>', result_string)
        self.assertIn(b'<item2>test2</item2>', result_string)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_options.set_flags.assert_called_once_with(
            mock_client_pywsman.FLAG_ENUMERATION_OPTIMIZATION)
        mock_options.set_max_elements.assert_called_once_with(100)
        mock_pywsman_client.enumerate.assert_called_once_with(
            mock_options, None, self.resource_uri)
Example #4
0
    def test__power_status(self, mock_gwc):
        namespace = resource_uris.CIM_AssociatedPowerManagementService
        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '2'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.POWER_ON, amt_power._power_status(self.node))

        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '8'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.POWER_OFF, amt_power._power_status(self.node))

        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '4'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.ERROR, amt_power._power_status(self.node))
Example #5
0
    def test_set_boot_device(self, mock_ccj, mock_cfcj, mock_glcv, mock_gbd,
                             mock_client_pywsman):
        controller_version = '2.1.5.0'
        mock_glcv.return_value = controller_version
        mock_gbd.return_value = {'boot_device': boot_devices.PXE,
                                 'persistent': True}
        result_xml_enum = test_utils.build_soap_xml(
            [{'InstanceID': 'NIC', 'BootSourceType': 'IPL'}],
            resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_SUCCESS}],
            resource_uris.DCIM_BootConfigSetting)

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            task.node = self.node
            result = self.driver.set_boot_device(task, boot_devices.PXE)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(
            mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, resource_uris.DCIM_BootConfigSetting,
            'ChangeBootOrderByInstanceID', None)
        mock_glcv.assert_called_once_with(self.node)
        mock_gbd.assert_called_once_with(self.node, controller_version)
        mock_cfcj.assert_called_once_with(self.node)
        mock_ccj.assert_called_once_with(self.node)
Example #6
0
    def test__power_status(self, mock_gwc):
        namespace = resource_uris.CIM_AssociatedPowerManagementService
        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '2'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.POWER_ON, amt_power._power_status(self.node))

        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '8'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.POWER_OFF, amt_power._power_status(self.node))

        result_xml = test_utils.build_soap_xml([{'PowerState':
                                                 '4'}],
                                               namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_client = mock_gwc.return_value
        mock_client.wsman_get.return_value = mock_doc
        self.assertEqual(
            states.ERROR, amt_power._power_status(self.node))
Example #7
0
    def test_set_boot_device(self, mock_ccj, mock_cfcj, mock_glcv, mock_gbd,
                             mock_client_pywsman):
        controller_version = '2.1.5.0'
        mock_glcv.return_value = controller_version
        mock_gbd.return_value = {'boot_device': boot_devices.PXE,
                                 'persistent': True}
        result_xml_enum = test_utils.build_soap_xml(
            [{'InstanceID': 'NIC', 'BootSourceType': 'IPL'}],
            resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_SUCCESS}],
            resource_uris.DCIM_BootConfigSetting)

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk

        with task_manager.acquire(self.context, self.node.uuid,
                                  shared=False) as task:
            task.node = self.node
            result = self.driver.set_boot_device(task, boot_devices.PXE)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(
            mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, resource_uris.DCIM_BootConfigSetting,
            'ChangeBootOrderByInstanceID', None)
        mock_glcv.assert_called_once_with(self.node)
        mock_gbd.assert_called_once_with(self.node, controller_version)
        mock_cfcj.assert_called_once_with(self.node)
        mock_ccj.assert_called_once_with(self.node)
Example #8
0
    def test__get_next_boot_list_onetime(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{
            'DCIM_BootConfigSetting': {
                'InstanceID': 'IPL',
                'IsNext': drac_mgmt.PERSISTENT
            }
        }, {
            'DCIM_BootConfigSetting': {
                'InstanceID': 'OneTime',
                'IsNext': drac_mgmt.ONE_TIME_BOOT
            }
        }], resource_uris.DCIM_BootConfigSetting)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        expected = {
            'instance_id': 'OneTime',
            'is_next': drac_mgmt.ONE_TIME_BOOT
        }
        result = drac_mgmt._get_next_boot_list(self.node)

        self.assertEqual(expected, result)
        mock_pywsman.enumerate.assert_called_once_with(
            mock.ANY, mock.ANY, resource_uris.DCIM_BootConfigSetting)
Example #9
0
    def test__set_power_state_fail(self, mock_power_pywsman,
                                   mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_ERROR,
              'Message': 'error message'}],
            resource_uris.DCIM_ComputerSystem)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        mock_pywsman_clientopts = (
            mock_client_pywsman.ClientOptions.return_value)

        self.assertRaises(exception.DracOperationFailed,
                          drac_power._set_power_state, self.node,
                          states.POWER_ON)

        mock_pywsman_clientopts.add_selector.assert_has_calls([
            mock.call('CreationClassName', 'DCIM_ComputerSystem'),
            mock.call('Name', 'srv:system')
        ], any_order=True)
        mock_pywsman_clientopts.add_property.assert_called_once_with(
            'RequestedState', '2')

        mock_pywsman_client.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_ComputerSystem, 'RequestStateChange', None)
Example #10
0
    def test__set_power_state_fail(self, mock_power_pywsman,
                                   mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{
            'ReturnValue': drac_client.RET_ERROR,
            'Message': 'error message'
        }], resource_uris.DCIM_ComputerSystem)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        mock_pywsman_clientopts = (
            mock_client_pywsman.ClientOptions.return_value)

        self.assertRaises(exception.DracOperationFailed,
                          drac_power._set_power_state, self.node,
                          states.POWER_ON)

        mock_pywsman_clientopts.add_selector.assert_has_calls([
            mock.call('CreationClassName', 'DCIM_ComputerSystem'),
            mock.call('Name', 'srv:system')
        ],
                                                              any_order=True)
        mock_pywsman_clientopts.add_property.assert_called_once_with(
            'RequestedState', '2')

        mock_pywsman_client.invoke.assert_called_once_with(
            mock.ANY, resource_uris.DCIM_ComputerSystem, 'RequestStateChange',
            None)
Example #11
0
    def test__set_power_state_fail(self, mock_power_pywsman,
                                   mock_client_pywsman):
        result_xml = test_utils.build_soap_xml({'ReturnValue': '1',
                                                'Message': 'error message'},
                                             resource_uris.DCIM_ComputerSystem)
        mock_xml_root = mock.Mock()
        mock_xml_root.string.return_value = result_xml

        mock_xml = mock.Mock()
        mock_xml.root.return_value = mock_xml_root

        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        mock_pywsman_clientopts = mock_power_pywsman.ClientOptions.return_value

        self.assertRaises(exception.DracOperationError,
                          drac_power._set_power_state, self.node,
                          states.POWER_ON)

        mock_pywsman_clientopts.add_selector.assert_has_calls([
            mock.call('CreationClassName', 'DCIM_ComputerSystem'),
            mock.call('Name', 'srv:system')
        ])
        mock_pywsman_clientopts.add_property.assert_called_once_with(
            'RequestedState', '2')

        mock_pywsman_client.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_ComputerSystem, 'RequestStateChange')
Example #12
0
    def test_wsman_invoke_with_properties_including_a_list(
            self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{
                'ReturnValue': drac_client.RET_SUCCESS
            }], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml
        mock_request_xml = mock_client_pywsman.XmlDoc.return_value

        method_name = 'method'
        properties = {'foo': ['bar', 'baz']}
        client = drac_client.Client(**INFO_DICT)
        client.wsman_invoke(self.resource_uri,
                            method_name,
                            properties=properties)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(
            mock_options, self.resource_uri, method_name, mock_request_xml)
        mock_request_xml.root().add.assert_has_calls([
            mock.call(self.resource_uri, 'foo', 'bar'),
            mock.call(self.resource_uri, 'foo', 'baz')
        ])
        self.assertEqual(2, mock_request_xml.root().add.call_count)
Example #13
0
    def test_xml_find(self):
        namespace = "http://fake"
        value = "fake_value"
        test_xml = test_utils.build_soap_xml([{"test_element": value}], namespace)
        mock_doc = test_utils.mock_wsman_root(test_xml)

        result = amt_common.xml_find(mock_doc, namespace, "test_element")
        self.assertEqual(value, result.text)
Example #14
0
def _set_config(responses=[]):
    ccj_xml = test_utils.build_soap_xml([{
        'DCIM_LifecycleJob': {
            'Name': 'fake'
        }
    }], resource_uris.DCIM_LifecycleJob)
    responses.append(test_utils.mock_wsman_root(ccj_xml))
    return _base_config(responses)
Example #15
0
    def test_xml_find(self):
        namespace = 'http://fake'
        value = 'fake_value'
        test_xml = test_utils.build_soap_xml([{'test_element': value}],
                                             namespace)
        mock_doc = test_utils.mock_wsman_root(test_xml)

        result = amt_common.xml_find(mock_doc, namespace, 'test_element')
        self.assertEqual(value, result.text)
Example #16
0
    def test_wsman_get_fail(self, mock_client_pywsman):
        namespace = amt_common._SOAP_ENVELOPE
        result_xml = test_utils.build_soap_xml([{"Fault": "fault"}], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.get.return_value = mock_doc
        client = amt_common.Client(**self.info)

        self.assertRaises(exception.AMTFailure, client.wsman_get, namespace)
        mock_pywsman.get.assert_called_once_with(mock.ANY, namespace)
Example #17
0
    def test_wsman_get_fail(self, mock_client_pywsman):
        namespace = amt_common._SOAP_ENVELOPE
        result_xml = test_utils.build_soap_xml([{'Fault': 'fault'}], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.get.return_value = mock_doc
        client = amt_common.Client(**self.info)

        self.assertRaises(exception.AMTFailure, client.wsman_get, namespace)
        mock_pywsman.get.assert_called_once_with(mock.ANY, namespace)
Example #18
0
    def test__enable_boot_config(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootService
        result_xml = test_utils.build_soap_xml([{"ReturnValue": "0"}], namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        amt_mgmt._enable_boot_config(self.node)

        mock_pywsman.invoke.assert_called_once_with(mock.ANY, namespace, "SetBootConfigRole", mock.ANY)
Example #19
0
    def test_wsman_get(self, mock_client_pywsman):
        namespace = resource_uris.CIM_AssociatedPowerManagementService
        result_xml = test_utils.build_soap_xml([{"PowerState": "2"}], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.get.return_value = mock_doc
        client = amt_common.Client(**self.info)

        client.wsman_get(namespace)
        mock_pywsman.get.assert_called_once_with(mock.ANY, namespace)
Example #20
0
    def test_set_boot_device_fail(self, mock_ccj, mock_cfcj, mock_client_pywsman):
        result_xml_enum = test_utils.build_soap_xml([{"InstanceID": "NIC"}], resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml(
            [{"ReturnValue": drac_common.RET_ERROR, "Message": "E_FAKE"}], resource_uris.DCIM_BootConfigSetting
        )

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk

        self.assertRaises(exception.DracOperationError, self.driver.set_boot_device, self.task, boot_devices.PXE)

        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, resource_uris.DCIM_BootConfigSetting, "ChangeBootOrderByInstanceID"
        )
        mock_cfcj.assert_called_once_with(self.node)
        self.assertFalse(mock_ccj.called)
Example #21
0
    def test__set_boot_device_order(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootConfigSetting
        device = boot_devices.PXE
        result_xml = test_utils.build_soap_xml([{"ReturnValue": "0"}], namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        amt_mgmt._set_boot_device_order(self.node, device)

        mock_pywsman.invoke.assert_called_once_with(mock.ANY, namespace, "ChangeBootOrder", mock.ANY)
Example #22
0
    def test__create_config_job_error(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{"ReturnValue": drac_common.RET_ERROR, "Message": "E_FAKE"}], resource_uris.DCIM_BIOSService
        )

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        self.assertRaises(exception.DracConfigJobCreationError, drac_mgmt._create_config_job, self.node)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY, resource_uris.DCIM_BIOSService, "CreateTargetedConfigJob")
Example #23
0
    def test__enable_boot_config(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootService
        result_xml = test_utils.build_soap_xml([{'ReturnValue': '0'}],
                                               namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        amt_mgmt._enable_boot_config(self.node)

        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, namespace, 'SetBootConfigRole', mock.ANY)
Example #24
0
    def test_wsman_get(self, mock_client_pywsman):
        namespace = resource_uris.CIM_AssociatedPowerManagementService
        result_xml = test_utils.build_soap_xml([{
            'PowerState': '2'
        }], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.get.return_value = mock_doc
        client = amt_common.Client(**self.info)

        client.wsman_get(namespace)
        mock_pywsman.get.assert_called_once_with(mock.ANY, namespace)
Example #25
0
    def test_wsman_invoke(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{"ReturnValue": drac_client.RET_SUCCESS}], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = "method"
        client = drac_client.Client(**INFO_DICT)
        client.wsman_invoke(self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(mock_options, self.resource_uri, method_name, None)
Example #26
0
    def test__check_for_config_job_already_exist(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{"DCIM_LifecycleJob": {"Name": "BIOS.Setup.1-1", "JobStatus": "scheduled", "InstanceID": "fake"}}],
            resource_uris.DCIM_LifecycleJob,
        )

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        self.assertRaises(exception.DracConfigJobCreationError, drac_mgmt._check_for_config_job, self.node)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_LifecycleJob)
Example #27
0
    def test_set_boot_device(self, mock_ccj, mock_cfcj, mock_client_pywsman):
        result_xml_enum = test_utils.build_soap_xml([{"InstanceID": "NIC"}], resource_uris.DCIM_BootSourceSetting)
        result_xml_invk = test_utils.build_soap_xml(
            [{"ReturnValue": drac_common.RET_SUCCESS}], resource_uris.DCIM_BootConfigSetting
        )

        mock_xml_enum = test_utils.mock_wsman_root(result_xml_enum)
        mock_xml_invk = test_utils.mock_wsman_root(result_xml_invk)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml_enum
        mock_pywsman.invoke.return_value = mock_xml_invk

        result = self.driver.set_boot_device(self.task, boot_devices.PXE)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, resource_uris.DCIM_BootConfigSetting, "ChangeBootOrderByInstanceID"
        )
        mock_cfcj.assert_called_once_with(self.node)
        mock_ccj.assert_called_once_with(self.node)
Example #28
0
    def test__get_power_state(self, mock_power_pywsman, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{'EnabledState': '2'}],
                                             resource_uris.DCIM_ComputerSystem)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.enumerate.return_value = mock_xml

        self.assertEqual(states.POWER_ON,
                         drac_power._get_power_state(self.node))

        mock_pywsman_client.enumerate.assert_called_once_with(mock.ANY,
            mock.ANY, resource_uris.DCIM_ComputerSystem)
Example #29
0
    def test_wsman_invoke_receives_unexpected_return_value(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{"ReturnValue": "42"}], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = "method"
        client = drac_client.Client(**INFO_DICT)
        self.assertRaises(exception.DracUnexpectedReturnValue, client.wsman_invoke, self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(mock_options, self.resource_uri, method_name, None)
Example #30
0
    def test__get_power_state(self, mock_power_pywsman, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{'EnabledState': '2'}],
                                             resource_uris.DCIM_ComputerSystem)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.enumerate.return_value = mock_xml

        self.assertEqual(states.POWER_ON,
                         drac_power._get_power_state(self.node))

        mock_pywsman_client.enumerate.assert_called_once_with(mock.ANY,
            mock.ANY, resource_uris.DCIM_ComputerSystem)
Example #31
0
    def test__set_boot_device_order(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootConfigSetting
        device = boot_devices.PXE
        result_xml = test_utils.build_soap_xml([{'ReturnValue': '0'}],
                                               namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        amt_mgmt._set_boot_device_order(self.node, device)

        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, namespace, 'ChangeBootOrder', mock.ANY)
Example #32
0
    def test_wsman_invoke_fail(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootSourceSetting
        result_xml = test_utils.build_soap_xml([{"ReturnValue": "2"}], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_doc
        method = "fake-method"
        options = mock.Mock(spec_set=[])

        client = amt_common.Client(**self.info)

        self.assertRaises(exception.AMTFailure, client.wsman_invoke, options, namespace, method)
        mock_pywsman.invoke.assert_called_once_with(options, namespace, method)
Example #33
0
    def test__check_for_config_job(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{"DCIM_LifecycleJob": {"Name": "fake"}}], resource_uris.DCIM_LifecycleJob
        )

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = drac_mgmt._check_for_config_job(self.node)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_LifecycleJob)
Example #34
0
    def test__create_config_job(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{"ReturnValue": drac_common.RET_SUCCESS}], resource_uris.DCIM_BIOSService
        )

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        result = drac_mgmt._create_config_job(self.node)

        self.assertIsNone(result)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY, resource_uris.DCIM_BIOSService, "CreateTargetedConfigJob")
Example #35
0
    def test__create_config_job(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_CREATED}],
            resource_uris.DCIM_BIOSService)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        result = drac_mgmt._create_config_job(self.node)

        self.assertIsNone(result)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_BIOSService, 'CreateTargetedConfigJob', None)
Example #36
0
    def test_get_boot_devices_persistent(self, mock_gnbm, mock_client_pywsman):
        mock_gnbm.return_value = {"instance_id": "IPL", "is_next": drac_mgmt.PERSISTENT}

        result_xml = test_utils.build_soap_xml([{"InstanceID": "NIC"}], resource_uris.DCIM_BootSourceSetting)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = self.driver.get_boot_device(self.task)
        expected = {"boot_device": boot_devices.PXE, "persistent": True}

        self.assertEqual(expected, result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
Example #37
0
    def test__enable_boot_config_fail(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootService
        result_xml = test_utils.build_soap_xml([{"ReturnValue": "2"}], namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        self.assertRaises(exception.AMTFailure, amt_mgmt._enable_boot_config, self.node)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY, namespace, "SetBootConfigRole", mock.ANY)

        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = None

        self.assertRaises(exception.AMTConnectFailure, amt_mgmt._enable_boot_config, self.node)
Example #38
0
    def test_get_boot_devices(self, mock_gnbm, mock_client_pywsman):
        mock_gnbm.return_value = {"instance_id": "OneTime", "is_next": drac_mgmt.ONE_TIME_BOOT}

        result_xml = test_utils.build_soap_xml([{"InstanceID": "HardDisk"}], resource_uris.DCIM_BootSourceSetting)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = self.driver.get_boot_device(self.task)
        expected = {"boot_device": boot_devices.DISK, "persistent": False}

        self.assertEqual(expected, result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY, resource_uris.DCIM_BootSourceSetting)
Example #39
0
    def test__get_lifecycle_controller_version(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'DCIM_SystemView': {'LifecycleControllerVersion': '42'}}],
            resource_uris.DCIM_SystemView)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = drac_mgmt._get_lifecycle_controller_version(self.node)

        self.assertEqual('42', result)
        mock_pywsman.enumerate.assert_called_once_with(
            mock.ANY, mock.ANY, resource_uris.DCIM_SystemView)
Example #40
0
    def test__create_config_job_error(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_ERROR,
              'Message': 'E_FAKE'}],
            resource_uris.DCIM_BIOSService)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        self.assertRaises(exception.DracOperationFailed,
                          drac_mgmt._create_config_job, self.node)
        mock_pywsman.invoke.assert_called_once_with(mock.ANY,
            resource_uris.DCIM_BIOSService, 'CreateTargetedConfigJob', None)
Example #41
0
    def test_wsman_invoke(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_SUCCESS}], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = 'method'
        client = drac_client.Client(**INFO_DICT)
        client.wsman_invoke(self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(
            mock_options, self.resource_uri, method_name, None)
Example #42
0
    def test__get_lifecycle_controller_version(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'DCIM_SystemView': {'LifecycleControllerVersion': '42'}}],
            resource_uris.DCIM_SystemView)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = drac_mgmt._get_lifecycle_controller_version(self.node)

        self.assertEqual('42', result)
        mock_pywsman.enumerate.assert_called_once_with(
            mock.ANY, mock.ANY, resource_uris.DCIM_SystemView)
Example #43
0
    def test__check_for_config_job(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{'DCIM_LifecycleJob':
                                                    {'Name': 'fake'}}],
                                          resource_uris.DCIM_LifecycleJob)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = drac_mgmt._check_for_config_job(self.node)

        self.assertIsNone(result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_LifecycleJob)
Example #44
0
    def test_wsman_invoke_receives_error_return_value(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{"ReturnValue": drac_client.RET_ERROR, "Message": "error message"}], self.resource_uri
        )
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = "method"
        client = drac_client.Client(**INFO_DICT)
        self.assertRaises(exception.DracOperationFailed, client.wsman_invoke, self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(mock_options, self.resource_uri, method_name, None)
Example #45
0
 def test_wsman_invoke(self, mock_client_pywsman):
     namespace = resource_uris.CIM_BootSourceSetting
     result_xml = test_utils.build_soap_xml([{"ReturnValue": "0"}], namespace)
     mock_doc = test_utils.mock_wsman_root(result_xml)
     mock_pywsman = mock_client_pywsman.Client.return_value
     mock_pywsman.invoke.return_value = mock_doc
     method = "ChangeBootOrder"
     options = mock.Mock(spec_set=[])
     client = amt_common.Client(**self.info)
     doc = None
     client.wsman_invoke(options, namespace, method, doc)
     mock_pywsman.invoke.assert_called_once_with(options, namespace, method)
     doc = "fake-input"
     client.wsman_invoke(options, namespace, method, doc)
     mock_pywsman.invoke.assert_called_with(options, namespace, method, doc)
Example #46
0
    def test__check_for_config_job_already_exist(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml([{'DCIM_LifecycleJob':
                                                    {'Name': 'BIOS.Setup.1-1',
                                                     'JobStatus': 'scheduled',
                                                     'InstanceID': 'fake'}}],
                                          resource_uris.DCIM_LifecycleJob)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        self.assertRaises(exception.DracPendingConfigJobExists,
                          drac_mgmt._check_for_config_job, self.node)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_LifecycleJob)
Example #47
0
    def test_wsman_invoke_retry(self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_SUCCESS}], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.side_effect = [None, mock_xml]

        method_name = 'method'
        client = drac_client.Client(**INFO_DICT)
        client.wsman_invoke(self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_has_calls([
            mock.call(mock_options, self.resource_uri, method_name, None),
            mock.call(mock_options, self.resource_uri, method_name, None)
        ])
Example #48
0
    def test_wsman_invoke_fail(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootSourceSetting
        result_xml = test_utils.build_soap_xml([{
            'ReturnValue': '2'
        }], namespace)
        mock_doc = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_doc
        method = 'fake-method'
        options = mock.Mock(spec_set=[])

        client = amt_common.Client(**self.info)

        self.assertRaises(exception.AMTFailure, client.wsman_invoke, options,
                          namespace, method)
        mock_pywsman.invoke.assert_called_once_with(options, namespace, method)
Example #49
0
 def test_wsman_invoke(self, mock_client_pywsman):
     namespace = resource_uris.CIM_BootSourceSetting
     result_xml = test_utils.build_soap_xml([{
         'ReturnValue': '0'
     }], namespace)
     mock_doc = test_utils.mock_wsman_root(result_xml)
     mock_pywsman = mock_client_pywsman.Client.return_value
     mock_pywsman.invoke.return_value = mock_doc
     method = 'ChangeBootOrder'
     options = mock.Mock(spec_set=[])
     client = amt_common.Client(**self.info)
     doc = None
     client.wsman_invoke(options, namespace, method, doc)
     mock_pywsman.invoke.assert_called_once_with(options, namespace, method)
     doc = 'fake-input'
     client.wsman_invoke(options, namespace, method, doc)
     mock_pywsman.invoke.assert_called_with(options, namespace, method, doc)
Example #50
0
    def test_get_boot_device(self, mock_gnbm, mock_client_pywsman):
        mock_gnbm.return_value = {'instance_id': 'OneTime',
                                  'is_next': drac_mgmt.ONE_TIME_BOOT}

        result_xml = test_utils.build_soap_xml([{'InstanceID': 'HardDisk'}],
                                      resource_uris.DCIM_BootSourceSetting)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = self.driver.get_boot_device(self.task)
        expected = {'boot_device': boot_devices.DISK, 'persistent': False}

        self.assertEqual(expected, result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_BootSourceSetting)
Example #51
0
    def test_get_boot_device_persistent(self, mock_gnbm, mock_client_pywsman):
        mock_gnbm.return_value = {'instance_id': 'IPL',
                                  'is_next': drac_mgmt.PERSISTENT}

        result_xml = test_utils.build_soap_xml([{'InstanceID': 'NIC'}],
                                      resource_uris.DCIM_BootSourceSetting)

        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.enumerate.return_value = mock_xml

        result = self.driver.get_boot_device(self.task)
        expected = {'boot_device': boot_devices.PXE, 'persistent': True}

        self.assertEqual(expected, result)
        mock_pywsman.enumerate.assert_called_once_with(mock.ANY, mock.ANY,
            resource_uris.DCIM_BootSourceSetting)
Example #52
0
    def test_wsman_invoke_receives_unexpected_return_value(
            self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': '42'}], self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = 'method'
        client = drac_client.Client(**INFO_DICT)
        self.assertRaises(exception.DracUnexpectedReturnValue,
                          client.wsman_invoke, self.resource_uri, method_name,
                          {}, {}, drac_client.RET_SUCCESS)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(
            mock_options, self.resource_uri, method_name, None)
Example #53
0
    def test__enable_boot_config_fail(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootService
        result_xml = test_utils.build_soap_xml([{'ReturnValue': '2'}],
                                               namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        self.assertRaises(exception.AMTFailure,
                          amt_mgmt._enable_boot_config, self.node)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, namespace, 'SetBootConfigRole', mock.ANY)

        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = None

        self.assertRaises(exception.AMTConnectFailure,
                          amt_mgmt._enable_boot_config, self.node)
Example #54
0
    def test_wsman_invoke_receives_error_return_value(
            self, mock_client_pywsman):
        result_xml = test_utils.build_soap_xml(
            [{'ReturnValue': drac_client.RET_ERROR,
              'Message': 'error message'}],
            self.resource_uri)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman_client = mock_client_pywsman.Client.return_value
        mock_pywsman_client.invoke.return_value = mock_xml

        method_name = 'method'
        client = drac_client.Client(**INFO_DICT)
        self.assertRaises(exception.DracOperationFailed,
                          client.wsman_invoke, self.resource_uri, method_name)

        mock_options = mock_client_pywsman.ClientOptions.return_value
        mock_pywsman_client.invoke.assert_called_once_with(
            mock_options, self.resource_uri, method_name, None)
Example #55
0
    def test__set_boot_device_order_fail(self, mock_client_pywsman):
        namespace = resource_uris.CIM_BootConfigSetting
        device = boot_devices.PXE
        result_xml = test_utils.build_soap_xml([{'ReturnValue': '2'}],
                                               namespace)
        mock_xml = test_utils.mock_wsman_root(result_xml)
        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = mock_xml

        self.assertRaises(exception.AMTFailure,
                          amt_mgmt._set_boot_device_order, self.node, device)
        mock_pywsman.invoke.assert_called_once_with(
            mock.ANY, namespace, 'ChangeBootOrder', mock.ANY)

        mock_pywsman = mock_client_pywsman.Client.return_value
        mock_pywsman.invoke.return_value = None

        self.assertRaises(exception.AMTConnectFailure,
                          amt_mgmt._set_boot_device_order, self.node, device)