示例#1
0
    def execute(self):
        data = None
        if self.nvram_mgr is not None:
            LOG.info('Fetching NVRAM.', instance=self.instance)
            data = self.nvram_mgr.fetch(self.instance)
            LOG.debug('NVRAM data is: %s', data, instance=self.instance)

        wrap = vm.create_lpar(self.adapter,
                              self.host_wrapper,
                              self.instance,
                              nvram=data,
                              slot_mgr=self.slot_mgr)
        pvm_stg.add_lpar_storage_scrub_tasks([wrap.id],
                                             self.stg_ftsk,
                                             lpars_exist=True)
        # If the stg_ftsk passed in was None and we initialized a
        # 'create_scrubber' stg_ftsk then run it immediately. We do
        # this because we moved the LPAR storage scrub tasks out of the
        # build_map initialization. This was so that we could construct the
        # build map earlier in the spawn, just before the LPAR is created.
        # Only rebuilds should be passing in None for stg_ftsk.
        if self.stg_ftsk.name == 'create_scrubber':
            LOG.info('Scrubbing storage as part of rebuild.',
                     instance=self.instance)
            self.stg_ftsk.execute()

        return wrap
示例#2
0
    def test_crt_lpar(self, mock_vld_all, mock_bld, mock_stdz, mock_ibmi):
        instance = objects.Instance(**powervm.TEST_INSTANCE)
        flavor = instance.get_flavor()
        flavor.extra_specs = {'powervm:dedicated_proc': 'true'}

        host_wrapper = mock.Mock()
        lparw = pvm_lpar.LPAR.wrap(self.resp.feed.entries[0])
        mock_bld.return_value = lparw
        self.apt.create.return_value = lparw.entry
        vm.create_lpar(self.apt, host_wrapper, instance, nvram='data')
        self.apt.create.assert_called_once_with(lparw,
                                                host_wrapper.schema_type,
                                                child_type='LogicalPartition',
                                                root_id=host_wrapper.uuid,
                                                service='uom',
                                                timeout=-1)
        mock_stdz.assert_called_once_with(host_wrapper,
                                          uncapped_weight=64,
                                          proc_units_factor=0.1)
        self.assertEqual(lparw.nvram, 'data')
        self.assertTrue(mock_vld_all.called)

        # Test srr and slot_mgr
        self.apt.reset_mock()
        mock_vld_all.reset_mock()
        mock_stdz.reset_mock()
        flavor.extra_specs = {'powervm:srr_capability': 'true'}
        self.apt.create.return_value = lparw.entry
        mock_slot_mgr = mock.Mock(build_map=mock.Mock(get_max_vslots=mock.Mock(
            return_value=123)))
        vm.create_lpar(self.apt,
                       host_wrapper,
                       instance,
                       slot_mgr=mock_slot_mgr)
        self.assertTrue(self.apt.create.called)
        self.assertTrue(mock_vld_all.called)
        self.assertTrue(lparw.srr_enabled)
        mock_stdz.assert_called_once_with(host_wrapper,
                                          uncapped_weight=64,
                                          proc_units_factor=0.1,
                                          max_slots=123)
        # The save is called with the LPAR's actual value, which in this mock
        # setup comes from lparw
        mock_slot_mgr.register_max_vslots.assert_called_with(
            lparw.io_config.max_virtual_slots)

        # Test to verify the LPAR Creation with invalid name specification
        mock_bld.side_effect = lpar_bld.LPARBuilderException("Invalid Name")
        host_wrapper = mock.Mock()
        self.assertRaises(exception.BuildAbortException, vm.create_lpar,
                          self.apt, host_wrapper, instance)

        resp = mock.Mock(status=202,
                         method='fake',
                         path='/dev/',
                         reason='Failure')
        mock_bld.side_effect = pvm_exc.HttpError(resp)
        try:
            vm.create_lpar(self.apt, host_wrapper, instance)
        except nvex.PowerVMAPIFailed as e:
            self.assertEqual(e.kwargs['inst_name'], instance.name)
            self.assertEqual(e.kwargs['reason'], mock_bld.side_effect)
        flavor.extra_specs = {'powervm:BADATTR': 'true'}
        host_wrapper = mock.Mock()
        self.assertRaises(exception.InvalidAttribute, vm.create_lpar, self.apt,
                          host_wrapper, instance)