Esempio n. 1
0
    def test_upload_new_vopt(self, mock_create_file):
        """Tests the uploads of the virtual disks."""

        mock_create_file.return_value = self._fake_meta()

        v_opt, f_wrap = ts.upload_vopt(self.adpt, self.v_uuid, None, 'test2',
                                       f_size=50)

        # Test that vopt was 'uploaded'
        self.adpt.upload_file.assert_called_with(mock.ANY, None)
        self.assertIsNone(f_wrap)
        self.assertIsNotNone(v_opt)
        self.assertIsInstance(v_opt, stor.VOptMedia)
        self.assertEqual('test2', v_opt.media_name)

        # Ensure cleanup was called
        self.adpt.delete.assert_called_once_with(
            'File', service='web',
            root_id='6233b070-31cc-4b57-99bd-37f80e845de9')

        # Test cleanup failure
        self.adpt.reset_mock()
        self.adpt.delete.side_effect = exc.Error('Something bad')

        vopt, f_wrap = ts.upload_vopt(self.adpt, self.v_uuid, None, 'test2',
                                      f_size=50)

        self.adpt.delete.assert_called_once_with(
            'File', service='web',
            root_id='6233b070-31cc-4b57-99bd-37f80e845de9')
        self.assertIsNotNone(f_wrap)
        self.assertIsNotNone(vopt)
        self.assertIsInstance(vopt, stor.VOptMedia)
        self.assertEqual('test2', v_opt.media_name)
Esempio n. 2
0
    def test_upload_new_vopt(self, mock_create_file):
        """Tests the uploads of the virtual disks."""

        mock_create_file.return_value = self._fake_meta()

        v_opt, f_wrap = ts.upload_vopt(self.adpt,
                                       self.v_uuid,
                                       None,
                                       'test2',
                                       f_size=50)

        # Test that vopt was 'uploaded'
        self.adpt.upload_file.assert_called_with(mock.ANY, None)
        self.assertIsNone(f_wrap)
        self.assertIsNotNone(v_opt)
        self.assertIsInstance(v_opt, stor.VOptMedia)
        self.assertEqual('test2', v_opt.media_name)

        # Ensure cleanup was called
        self.adpt.delete.assert_called_once_with(
            'File',
            service='web',
            root_id='6233b070-31cc-4b57-99bd-37f80e845de9')

        # Test cleanup failure
        self.adpt.reset_mock()
        self.adpt.delete.side_effect = exc.Error('Something bad')

        vopt, f_wrap = ts.upload_vopt(self.adpt,
                                      self.v_uuid,
                                      None,
                                      'test2',
                                      f_size=50)

        self.adpt.delete.assert_called_once_with(
            'File',
            service='web',
            root_id='6233b070-31cc-4b57-99bd-37f80e845de9')
        self.assertIsNotNone(f_wrap)
        self.assertIsNotNone(vopt)
        self.assertIsInstance(vopt, stor.VOptMedia)
        self.assertEqual('test2', v_opt.media_name)
Esempio n. 3
0
    def create_cfg_drv_vopt(self,
                            instance,
                            injected_files,
                            network_info,
                            stg_ftsk,
                            admin_pass=None,
                            mgmt_cna=None):
        """Create the config drive virtual optical and attach to VM.

        :param instance: The VM instance from OpenStack.
        :param injected_files: A list of file paths that will be injected into
                               the ISO.
        :param network_info: The network_info from the nova spawn method.
        :param stg_ftsk: FeedTask to defer storage connectivity operations.
        :param admin_pass: (Optional) password to inject for the VM.
        :param mgmt_cna: (Optional) The management (RMC) CNA wrapper.
        """
        # If there is a management client network adapter, then we should
        # convert that to a VIF and add it to the network info
        if mgmt_cna is not None:
            network_info = copy.deepcopy(network_info)
            network_info.append(self._mgmt_cna_to_vif(mgmt_cna))

        # Pick a file name for when we upload the media to VIOS
        file_name = pvm_util.sanitize_file_name_for_api(
            instance.uuid.replace('-', ''),
            prefix='cfg_',
            suffix='.iso',
            max_len=pvm_const.MaxLen.VOPT_NAME)

        # Create and upload the media
        with tempfile.NamedTemporaryFile(mode='rb') as fh:
            self._create_cfg_dr_iso(instance,
                                    injected_files,
                                    network_info,
                                    fh.name,
                                    admin_pass=admin_pass)
            vopt, f_uuid = tsk_stg.upload_vopt(self.adapter, self.vios_uuid,
                                               fh, file_name,
                                               os.path.getsize(fh.name))

        # Define the function to build and add the mapping
        def add_func(vios_w):
            LOG.info("Adding cfg drive mapping to Virtual I/O Server %s.",
                     vios_w.name,
                     instance=instance)
            mapping = tsk_map.build_vscsi_mapping(None, vios_w,
                                                  vm.get_pvm_uuid(instance),
                                                  vopt)
            return tsk_map.add_map(vios_w, mapping)

        # Add the subtask to create the mapping when the FeedTask runs
        stg_ftsk.wrapper_tasks[self.vios_uuid].add_functor_subtask(add_func)
Esempio n. 4
0
    def create_cfg_drv_vopt(self,
                            instance,
                            injected_files,
                            network_info,
                            stg_ftsk,
                            admin_pass=None,
                            mgmt_cna=None):
        """Create the config drive virtual optical and attach to VM.

        :param instance: The VM instance from OpenStack.
        :param injected_files: A list of file paths that will be injected into
                               the ISO.
        :param network_info: The network_info from the nova spawn method.
        :param stg_ftsk: FeedTask to defer storage connectivity operations.
        :param admin_pass: (Optional) password to inject for the VM.
        :param mgmt_cna: (Optional) The management (RMC) CNA wrapper.
        """
        # If there is a management client network adapter, then we should
        # convert that to a VIF and add it to the network info
        if mgmt_cna is not None:
            network_info = copy.deepcopy(network_info)
            network_info.append(self._mgmt_cna_to_vif(mgmt_cna))

        iso_path, file_name = self._create_cfg_dr_iso(instance,
                                                      injected_files,
                                                      network_info,
                                                      admin_pass=admin_pass)

        # Upload the media
        with open(iso_path, 'rb') as d_stream:
            vopt, f_uuid = tsk_stg.upload_vopt(self.adapter, self.vios_uuid,
                                               d_stream, file_name,
                                               os.path.getsize(iso_path))

        # The media can be removed now that the upload is complete
        os.remove(iso_path)

        # Define the function to build and add the mapping
        def add_func(vios_w):
            LOG.info("Adding cfg drive mapping to Virtual I/O Server %s.",
                     vios_w.name,
                     instance=instance)
            mapping = tsk_map.build_vscsi_mapping(None, vios_w,
                                                  vm.get_pvm_uuid(instance),
                                                  vopt)
            return tsk_map.add_map(vios_w, mapping)

        # Add the subtask to create the mapping when the FeedTask runs
        stg_ftsk.wrapper_tasks[self.vios_uuid].add_functor_subtask(add_func)
Esempio n. 5
0
    def create_cfg_drv_vopt(self,
                            instance,
                            injected_files,
                            network_info,
                            lpar_uuid,
                            admin_pass=None,
                            mgmt_cna=None,
                            stg_ftsk=None):
        """Creates the config drive virtual optical and attach to VM.

        :param instance: The VM instance from OpenStack.
        :param injected_files: A list of file paths that will be injected into
                               the ISO.
        :param network_info: The network_info from the nova spawn method.
        :param lpar_uuid: The UUID of the client LPAR
        :param admin_pass: (Optional) password to inject for the VM.
        :param mgmt_cna: (Optional) The management (RMC) CNA wrapper.
        :param stg_ftsk: (Optional) If provided, the tasks to create and attach
                         the Media to the VM will be deferred on to the
                         FeedTask passed in.  The execute can be done all in
                         one method (batched together).  If None (the default),
                         the media will be created and attached immediately.
        """
        # If there is a management client network adapter, then we should
        # convert that to a VIF and add it to the network info
        if mgmt_cna is not None and CONF.powervm.use_rmc_ipv6_scheme:
            network_info = copy.deepcopy(network_info)
            network_info.append(self._mgmt_cna_to_vif(mgmt_cna))

        # Pick a file name for when we upload the media to VIOS
        file_name = self.get_cfg_drv_name(instance)

        # Create and upload the media
        with tempfile.NamedTemporaryFile(mode='rb') as fh:
            self._create_cfg_dr_iso(instance,
                                    injected_files,
                                    network_info,
                                    fh.name,
                                    admin_pass=admin_pass)
            vopt, f_uuid = tsk_stg.upload_vopt(self.adapter, self.vios_uuid,
                                               fh, file_name,
                                               os.path.getsize(fh.name))

        # Run the attach of the virtual optical
        self._attach_vopt(instance, lpar_uuid, vopt, stg_ftsk)
Esempio n. 6
0
    def create_cfg_drv_vopt(self, instance, injected_files, network_info,
                            stg_ftsk, admin_pass=None, mgmt_cna=None):
        """Create the config drive virtual optical and attach to VM.

        :param instance: The VM instance from OpenStack.
        :param injected_files: A list of file paths that will be injected into
                               the ISO.
        :param network_info: The network_info from the nova spawn method.
        :param stg_ftsk: FeedTask to defer storage connectivity operations.
        :param admin_pass: (Optional) password to inject for the VM.
        :param mgmt_cna: (Optional) The management (RMC) CNA wrapper.
        """
        # If there is a management client network adapter, then we should
        # convert that to a VIF and add it to the network info
        if mgmt_cna is not None:
            network_info = copy.deepcopy(network_info)
            network_info.append(self._mgmt_cna_to_vif(mgmt_cna))

        # Pick a file name for when we upload the media to VIOS
        file_name = pvm_util.sanitize_file_name_for_api(
            instance.uuid.replace('-', ''), prefix='cfg_', suffix='.iso',
            max_len=pvm_const.MaxLen.VOPT_NAME)

        # Create and upload the media
        with tempfile.NamedTemporaryFile(mode='rb') as fh:
            self._create_cfg_dr_iso(instance, injected_files, network_info,
                                    fh.name, admin_pass=admin_pass)
            vopt, f_uuid = tsk_stg.upload_vopt(
                self.adapter, self.vios_uuid, fh, file_name,
                os.path.getsize(fh.name))

        # Define the function to build and add the mapping
        def add_func(vios_w):
            LOG.info("Adding cfg drive mapping to Virtual I/O Server %s.",
                     vios_w.name, instance=instance)
            mapping = tsk_map.build_vscsi_mapping(
                None, vios_w, vm.get_pvm_uuid(instance), vopt)
            return tsk_map.add_map(vios_w, mapping)

        # Add the subtask to create the mapping when the FeedTask runs
        stg_ftsk.wrapper_tasks[self.vios_uuid].add_functor_subtask(add_func)
Esempio n. 7
0
    def create_cfg_drv_vopt(self, instance, injected_files, network_info,
                            stg_ftsk, admin_pass=None, mgmt_cna=None):
        """Create the config drive virtual optical and attach to VM.

        :param instance: The VM instance from OpenStack.
        :param injected_files: A list of file paths that will be injected into
                               the ISO.
        :param network_info: The network_info from the nova spawn method.
        :param stg_ftsk: FeedTask to defer storage connectivity operations.
        :param admin_pass: (Optional) password to inject for the VM.
        :param mgmt_cna: (Optional) The management (RMC) CNA wrapper.
        """
        # If there is a management client network adapter, then we should
        # convert that to a VIF and add it to the network info
        if mgmt_cna is not None:
            network_info = copy.deepcopy(network_info)
            network_info.append(self._mgmt_cna_to_vif(mgmt_cna))

        iso_path, file_name = self._create_cfg_dr_iso(
            instance, injected_files, network_info, admin_pass=admin_pass)

        # Upload the media
        with open(iso_path, 'rb') as d_stream:
            vopt, f_uuid = tsk_stg.upload_vopt(
                self.adapter, self.vios_uuid, d_stream, file_name,
                os.path.getsize(iso_path))

        # The media can be removed now that the upload is complete
        os.remove(iso_path)

        # Define the function to build and add the mapping
        def add_func(vios_w):
            LOG.info("Adding cfg drive mapping to Virtual I/O Server %s.",
                     vios_w.name, instance=instance)
            mapping = tsk_map.build_vscsi_mapping(
                None, vios_w, vm.get_pvm_uuid(instance), vopt)
            return tsk_map.add_map(vios_w, mapping)

        # Add the subtask to create the mapping when the FeedTask runs
        stg_ftsk.wrapper_tasks[self.vios_uuid].add_functor_subtask(add_func)
Esempio n. 8
0
 def _upload_vopt(self, iso_path, file_name, file_size):
     with open(iso_path, 'rb') as d_stream:
         return tsk_stg.upload_vopt(self.adapter, self.vios_uuid, d_stream,
                                    file_name, file_size)
Esempio n. 9
0
 def _upload_vopt(self, iso_path, file_name, file_size):
     with open(iso_path, 'rb') as d_stream:
         return tsk_stg.upload_vopt(self.adapter, self.vios_uuid, d_stream,
                                    file_name, file_size)