Exemplo n.º 1
0
    def test_instance_info(self):
        inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234')
        # Test the static properties
        self.assertEqual(inst_info.id, '1234')
        self.assertEqual(inst_info.cpu_time_ns, 0)

        # Check that we raise an exception if the instance is gone.
        self.apt.read.side_effect = pvm_exc.HttpNotFound(
            mock.MagicMock(status=404))
        self.assertRaises(exception.InstanceNotFound,
                          inst_info.__getattribute__, 'state')

        # Reset the test inst_info
        inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234')

        class FakeResp2(object):
            def __init__(self, body):
                self.body = '"%s"' % body

        self.apt.read.side_effect = None
        self.apt.read.return_value = FakeResp2('running')
        self.assertEqual(inst_info.state, power_state.RUNNING)

        # Check the __eq__ method
        inst_info1 = vm.InstanceInfo(self.apt, 'inst_name', '1234')
        inst_info2 = vm.InstanceInfo(self.apt, 'inst_name', '1234')
        self.assertEqual(inst_info1, inst_info2)
        inst_info2 = vm.InstanceInfo(self.apt, 'name', '4321')
        self.assertNotEqual(inst_info1, inst_info2)
Exemplo n.º 2
0
    def test_get_vm_qp(self):
        def adapter_read(root_type,
                         root_id=None,
                         suffix_type=None,
                         suffix_parm=None,
                         helpers=None):
            json_str = (u'{"IsVirtualServiceAttentionLEDOn":"false","Migration'
                        u'State":"Not_Migrating","CurrentProcessingUnits":0.1,'
                        u'"ProgressState":null,"PartitionType":"AIX/Linux","Pa'
                        u'rtitionID":1,"AllocatedVirtualProcessors":1,"Partiti'
                        u'onState":"not activated","RemoteRestartState":"Inval'
                        u'id","OperatingSystemVersion":"Unknown","AssociatedMa'
                        u'nagedSystem":"https://9.1.2.3:12443/rest/api/uom/Man'
                        u'agedSystem/98498bed-c78a-3a4f-b90a-4b715418fcb6","RM'
                        u'CState":"inactive","PowerManagementMode":null,"Parti'
                        u'tionName":"lpar-1-06674231-lpar","HasDedicatedProces'
                        u'sors":"false","ResourceMonitoringIPAddress":null,"Re'
                        u'ferenceCode":"00000000","CurrentProcessors":null,"Cu'
                        u'rrentMemory":512,"SharingMode":"uncapped"}')
            self.assertEqual('LogicalPartition', root_type)
            self.assertEqual('lpar_uuid', root_id)
            self.assertEqual('quick', suffix_type)
            resp = mock.MagicMock()
            if suffix_parm is None:
                resp.body = json_str
            elif suffix_parm == 'PartitionID':
                resp.body = '1'
            elif suffix_parm == 'CurrentProcessingUnits':
                resp.body = '0.1'
            elif suffix_parm == 'AssociatedManagedSystem':
                # The double quotes are important
                resp.body = ('"https://9.1.2.3:12443/rest/api/uom/ManagedSyste'
                             'm/98498bed-c78a-3a4f-b90a-4b715418fcb6"')
            else:
                self.fail('Unhandled quick property key %s' % suffix_parm)
            return resp

        def adpt_read_no_log(*args, **kwds):
            helpers = kwds['helpers']
            try:
                helpers.index(pvm_log.log_helper)
            except ValueError:
                # Successful path since the logger shouldn't be there
                return adapter_read(*args, **kwds)

            self.fail('Log helper was found when it should not be')

        ms_href = ('https://9.1.2.3:12443/rest/api/uom/ManagedSystem/98498bed-'
                   'c78a-3a4f-b90a-4b715418fcb6')
        self.apt.read.side_effect = adapter_read
        self.assertEqual(1, vm.get_vm_id(self.apt, 'lpar_uuid'))
        self.assertEqual(
            ms_href,
            vm.get_vm_qp(self.apt, 'lpar_uuid', 'AssociatedManagedSystem'))
        self.apt.read.side_effect = adpt_read_no_log
        self.assertEqual(
            0.1,
            vm.get_vm_qp(self.apt,
                         'lpar_uuid',
                         'CurrentProcessingUnits',
                         log_errors=False))
        qp_dict = vm.get_vm_qp(self.apt, 'lpar_uuid', log_errors=False)
        self.assertEqual(ms_href, qp_dict['AssociatedManagedSystem'])
        self.assertEqual(1, qp_dict['PartitionID'])
        self.assertEqual(0.1, qp_dict['CurrentProcessingUnits'])

        resp = mock.MagicMock()
        resp.status = 404
        self.apt.read.side_effect = pvm_exc.HttpNotFound(resp)
        self.assertRaises(exception.InstanceNotFound,
                          vm.get_vm_qp,
                          self.apt,
                          'lpar_uuid',
                          log_errors=False)

        self.apt.read.side_effect = pvm_exc.Error("message", response=None)
        self.assertRaises(pvm_exc.Error,
                          vm.get_vm_qp,
                          self.apt,
                          'lpar_uuid',
                          log_errors=False)

        resp.status = 500
        self.apt.read.side_effect = pvm_exc.Error("message", response=resp)
        self.assertRaises(pvm_exc.Error,
                          vm.get_vm_qp,
                          self.apt,
                          'lpar_uuid',
                          log_errors=False)
Exemplo n.º 3
0
 def test_get_instance_wrapper(self, mock_get):
     mock_get.side_effect = pvm_exc.HttpNotFound(resp=mock.Mock(status=404))
     instance = objects.Instance(**powervm.TEST_INSTANCE)
     # vm.get_instance_wrapper(self.apt, instance, 'lpar_uuid')
     self.assertRaises(exception.InstanceNotFound, vm.get_instance_wrapper,
                       self.apt, instance, 'lpar_uuid')
Exemplo n.º 4
0
    def test_dlt_lpar(self, mock_vterm, mock_pvm_uuid):
        """Performs a delete LPAR test."""
        mock_pvm_uuid.return_value = 'pvm_uuid'

        vm.delete_lpar(self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_called_once_with('LogicalPartition',
                                                root_id='pvm_uuid')

        # Test Failure Path
        # build a mock response body with the expected HSCL msg
        resp = mock.Mock(body='error msg: HSCL151B more text')
        self.apt.delete.side_effect = pvm_exc.Error('Mock Error Message',
                                                    response=resp)

        # Reset counters
        mock_pvm_uuid.reset_mock()
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        self.assertRaises(pvm_exc.Error, vm.delete_lpar, self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_called_once_with('LogicalPartition',
                                                root_id='pvm_uuid')

        # Test HttpNotFound - exception not raised
        mock_pvm_uuid.reset_mock()
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        resp.status = 404
        self.apt.delete.side_effect = pvm_exc.HttpNotFound(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_called_once_with('LogicalPartition',
                                                root_id='pvm_uuid')

        # Test Other HttpError
        mock_pvm_uuid.reset_mock()
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        resp.status = 111
        self.apt.delete.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_called_once_with('LogicalPartition',
                                                root_id='pvm_uuid')

        # Test HttpNotFound closing vterm
        mock_pvm_uuid.reset_mock()
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        resp.status = 404
        mock_vterm.side_effect = pvm_exc.HttpNotFound(resp=resp)
        vm.delete_lpar(self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_not_called()

        # Test Other HttpError closing vterm
        mock_pvm_uuid.reset_mock()
        self.apt.reset_mock()
        mock_vterm.reset_mock()

        resp.status = 111
        mock_vterm.side_effect = pvm_exc.HttpError(resp=resp)
        self.assertRaises(pvm_exc.HttpError, vm.delete_lpar, self.apt, 'inst')
        mock_pvm_uuid.assert_called_once_with('inst')
        mock_vterm.assert_called_once_with(self.apt, 'pvm_uuid')
        self.apt.delete.assert_not_called()
Exemplo n.º 5
0
 def test_store_with_not_found_exc(self, mock_get_inst, mock_log):
     mock_get_inst.side_effect = pvm_exc.HttpNotFound(mock.Mock())
     mgr = manager.NvramManager(self.fake_store, mock.Mock(), mock.Mock())
     mgr.store(powervm.TEST_INST1.uuid)
     self.assertEqual(0, mock_log.call_count)