示例#1
0
    def test_abstract_io_apis(self):
        """Get NotImplementedError from abstract I/O APIs."""
        ins = VMDescription(self.TEXT_FILE, self.TEXT_FILE)

        self.assertRaises(NotImplementedError,
                          ins.write)

        self.assertRaises(NotImplementedError, ins.predicted_output_size)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#2
0
    def test_abstract_info_apis(self):
        """Get NotImplementedError from abstract info APIs."""
        ins = VMDescription(self.TEXT_FILE, None)

        with self.assertRaises(NotImplementedError):
            assert ins.platform
        self.assertRaises(NotImplementedError,
                          ins.info_string)
        self.assertRaises(NotImplementedError,
                          ins.profile_info_string)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#3
0
    def test_generic_instance_apis(self):
        """Verify APIs with generic implementations."""
        ins = VMDescription(self.TEXT_FILE, None)
        self.assertEqual(ins.input_file, self.TEXT_FILE)
        self.assertEqual(ins.output_file, None)
        self.assertTrue(os.path.exists(ins.working_dir))

        ins.output_file = self.TEXT_FILE
        self.assertEqual(ins.output_file, self.TEXT_FILE)

        out = ins.convert_disk_if_needed(self.TEXT_FILE, None)
        self.assertEqual(out, self.TEXT_FILE)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#4
0
    def test_context_manager(self, write, rmtree, *_):
        """Verify context manager logic."""
        # Successful exit - write() is called and working_dir is cleaned up
        with VMDescription("foo.txt", None):
            pass
        write.assert_called_once()
        rmtree.assert_called_once_with("/foo/bar")

        write.reset_mock()
        rmtree.reset_mock()

        # Error exit - cleanup still happens but write() is not called
        with self.assertRaises(RuntimeError):
            with VMDescription("foo.txt", None):
                raise RuntimeError("Gotcha!")
        write.assert_not_called()
        rmtree.assert_called_once_with("/foo/bar")
示例#5
0
    def test_abstract_disk_file_apis(self):
        """Get NotImplementedError from abstract disk and file APIs."""
        ins = VMDescription(self.TEXT_FILE, None)

        self.assertRaises(NotImplementedError,
                          ins.search_from_filename, self.TEXT_FILE)
        self.assertRaises(NotImplementedError,
                          ins.search_from_file_id, None)
        self.assertRaises(NotImplementedError,
                          ins.search_from_controller, None, None)
        self.assertRaises(NotImplementedError,
                          ins.find_open_controller, None)
        self.assertRaises(NotImplementedError,
                          ins.get_id_from_file, None)
        self.assertRaises(NotImplementedError,
                          ins.get_path_from_file, None)
        self.assertRaises(NotImplementedError,
                          ins.get_file_ref_from_disk, None)
        self.assertRaises(NotImplementedError,
                          ins.get_id_from_disk, None)
        self.assertRaises(NotImplementedError,
                          ins.get_common_subtype, None)
        self.assertRaises(NotImplementedError,
                          ins.check_sanity_of_disk_device,
                          None, None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_file, self.TEXT_FILE, None)
        self.assertRaises(NotImplementedError,
                          ins.remove_file, self.TEXT_FILE)
        self.assertRaises(NotImplementedError,
                          ins.remove_file, self.TEXT_FILE, None)
        self.assertRaises(NotImplementedError,
                          ins.remove_file, self.TEXT_FILE, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_disk, self.TEXT_FILE, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_controller_device, None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_disk_device,
                          None, None, None, None, None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.find_empty_drive, None)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#6
0
    def test_abstract_hardware_apis(self):
        """Get NotImplementedError from abstract hardware APIs."""
        ins = VMDescription(self.TEXT_FILE, None)

        with self.assertRaises(NotImplementedError):
            ins.validate_hardware()
        with self.assertRaises(NotImplementedError):
            assert ins.config_profiles
        with self.assertRaises(NotImplementedError):
            assert ins.default_config_profile
        self.assertRaises(NotImplementedError,
                          ins.create_configuration_profile,
                          None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.delete_configuration_profile, None)
        with self.assertRaises(NotImplementedError):
            assert ins.system_types
        with self.assertRaises(NotImplementedError):
            ins.system_types = ["hello", "world"]
        self.assertRaises(NotImplementedError,
                          ins.set_cpu_count, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.set_memory, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_type, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_types, None, None)
        self.assertRaises(NotImplementedError,
                          ins.get_nic_count, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_count, 0, None)
        with self.assertRaises(NotImplementedError):
            assert ins.networks
        with self.assertRaises(NotImplementedError):
            assert ins.network_descriptions
        self.assertRaises(NotImplementedError,
                          ins.create_network, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_networks, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_mac_addresses, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_names, None, None)
        self.assertRaises(NotImplementedError,
                          ins.get_serial_count, None)
        self.assertRaises(NotImplementedError,
                          ins.set_serial_count, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.get_serial_connectivity, None)
        self.assertRaises(NotImplementedError,
                          ins.set_serial_connectivity, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_scsi_subtype, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_ide_subtype, None, None)
        self.assertRaises(NotImplementedError,
                          ins.find_device_location, None)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#7
0
 def package(self, value):
     if value is not None and not os.path.exists(value):
         raise InvalidInputError(
             "Specified package {0} does not exist!".format(value))
     if self.vm is not None:
         self.vm.destroy()
         self.vm = None
     if value is not None:
         self.vm = VMDescription.factory(value, None)
     self._package = value
示例#8
0
    def test_abstract_property_apis(self):
        """Get NotImplementedError from abstract property APIs."""
        ins = VMDescription(self.TEXT_FILE, None)

        with self.assertRaises(NotImplementedError):
            assert ins.environment_properties
        with self.assertRaises(NotImplementedError):
            assert ins.environment_transports
        with self.assertRaises(NotImplementedError):
            ins.environment_transports = ['iso']
        self.assertRaises(NotImplementedError,
                          ins.get_property_value, None)
        self.assertRaises(NotImplementedError,
                          ins.set_property_value, None, None)
        self.assertRaises(NotImplementedError,
                          ins.config_file_to_properties, self.TEXT_FILE)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#9
0
 def package(self, value):
     if value is not None and not os.path.exists(value):
         raise InvalidInputError("Specified package {0} does not exist!"
                                 .format(value))
     if self.vm is not None:
         self.vm.destroy()
         self.vm = None
     if value is not None:
         self.vm = VMDescription.factory(value, None)
     self._package = value
示例#10
0
    def test_generic_instance_apis(self):
        """Verify APIs with generic implementations."""
        ins = VMDescription(self.TEXT_FILE, None)
        self.assertEqual(ins.input_file, self.TEXT_FILE)
        self.assertEqual(ins.output_file, None)
        self.assertTrue(os.path.exists(ins.working_dir))

        ins.output_file = self.TEXT_FILE
        self.assertEqual(ins.output_file, self.TEXT_FILE)

        ins.product_class = 'generic'
        self.assertEqual(ins.product_class, 'generic')

        out = ins.convert_disk_if_needed(self.TEXT_FILE, None)
        self.assertEqual(out, self.TEXT_FILE)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#11
0
    def test_abstract_product_apis(self):
        """Get NotImplementedError from abstract product APIs."""
        ins = VMDescription(self.TEXT_FILE, None)

        with self.assertRaises(NotImplementedError):
            assert ins.version_short
        with self.assertRaises(NotImplementedError):
            ins.version_short = "hello"
        with self.assertRaises(NotImplementedError):
            assert ins.version_long
        with self.assertRaises(NotImplementedError):
            ins.version_long = "hello world!"

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))
示例#12
0
    def run(self):
        """Do the actual work of this command.

        Raises:
          InvalidInputError: if :func:`ready_to_run` reports ``False``
        """
        super(COTInfo, self).run()

        first = True
        # TODO: UI should provide an "output" method or similar,
        #       so that we don't call print directly here.
        for package in self.package_list:
            if not first:
                print("")
            try:
                with VMDescription.factory(package, None) as vm:
                    print(vm.info_string(self.ui.terminal_width - 1,
                                         self.verbosity))
            except VMInitError as exc:
                logger.error("Unable to display information for %s: %s",
                             package, exc.strerror)
            first = False
示例#13
0
    def package(self,   # pylint: disable=missing-type-doc,missing-param-doc
                value):
        """VM description file to read (and write to unless ``output`` is set).

        Calls :meth:`COT.vm_description.VMDescription.factory` to instantiate
        :attr:`self.vm` from the provided file.

        Raises:
          InvalidInputError: if the file does not exist.
          SystemExit: if available disk space versus predicted amount required
            for output is insufficient, and the user declines to continue
            in response to this information.
        """
        if value is not None and not os.path.exists(value):
            raise InvalidInputError("Specified package {0} does not exist!"
                                    .format(value))
        if self.vm is not None:
            self.vm.destroy()
            self.vm = None
        if value is not None:
            # Unlike ReadCommand, we pass self.output to the VM factory
            self.vm = VMDescription.factory(value, self.output)
        self._package = value
示例#14
0
    def package(
            self,  # pylint: disable=missing-type-doc,missing-param-doc
            value):
        """VM description file to read (and write to unless ``output`` is set).

        Calls :meth:`COT.vm_description.VMDescription.factory` to instantiate
        :attr:`self.vm` from the provided file.

        Raises:
          InvalidInputError: if the file does not exist.
          SystemExit: if available disk space versus predicted amount required
            for output is insufficient, and the user declines to continue
            in response to this information.
        """
        if value is not None and not os.path.exists(value):
            raise InvalidInputError(
                "Specified package {0} does not exist!".format(value))
        if self.vm is not None:
            self.vm.destroy()
            self.vm = None
        if value is not None:
            # Unlike ReadCommand, we pass self.output to the VM factory
            self.vm = VMDescription.factory(value, self.output)
        self._package = value
示例#15
0
    def test_abstract_instance_apis(self):
        """Verify NotImplementedError from APIs that have no generic form."""
        ins = VMDescription(self.TEXT_FILE, None)

        self.assertRaises(NotImplementedError,
                          ins.write)
        with self.assertRaises(NotImplementedError):
            ins.platform

        self.assertRaises(NotImplementedError,
                          ins.search_from_filename, self.TEXT_FILE)
        self.assertRaises(NotImplementedError,
                          ins.search_from_file_id, None)
        self.assertRaises(NotImplementedError,
                          ins.search_from_controller, None, None)
        self.assertRaises(NotImplementedError,
                          ins.find_open_controller, None)
        self.assertRaises(NotImplementedError,
                          ins.get_id_from_file, None)
        self.assertRaises(NotImplementedError,
                          ins.get_path_from_file, None)
        self.assertRaises(NotImplementedError,
                          ins.get_file_ref_from_disk, None)
        self.assertRaises(NotImplementedError,
                          ins.get_type_from_device, None)
        self.assertRaises(NotImplementedError,
                          ins.get_subtype_from_device, None)
        self.assertRaises(NotImplementedError,
                          ins.get_common_subtype, None)
        self.assertRaises(NotImplementedError,
                          ins.check_sanity_of_disk_device,
                          None, None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_file, self.TEXT_FILE, None)
        self.assertRaises(NotImplementedError,
                          ins.add_disk, self.TEXT_FILE, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_controller_device, None, None, None)
        self.assertRaises(NotImplementedError,
                          ins.add_disk_device,
                          None, None, None, None, None, None, None)

        with self.assertRaises(NotImplementedError):
            ins.config_profiles
        with self.assertRaises(NotImplementedError):
            ins.default_config_profile
        self.assertRaises(NotImplementedError,
                          ins.create_configuration_profile,
                          None, None, None)
        with self.assertRaises(NotImplementedError):
            ins.system_types
        with self.assertRaises(NotImplementedError):
            ins.system_types = ["hello", "world"]
        self.assertRaises(NotImplementedError,
                          ins.set_cpu_count, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.set_memory, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_type, None, None)
        self.assertRaises(NotImplementedError,
                          ins.get_nic_count, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_count, 0, None)
        with self.assertRaises(NotImplementedError):
            ins.networks
        self.assertRaises(NotImplementedError,
                          ins.create_network, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_networks, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_mac_addresses, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_nic_names, None, None)
        self.assertRaises(NotImplementedError,
                          ins.get_serial_count, None)
        self.assertRaises(NotImplementedError,
                          ins.set_serial_count, 0, None)
        self.assertRaises(NotImplementedError,
                          ins.set_serial_connectivity, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_scsi_subtype, None, None)
        self.assertRaises(NotImplementedError,
                          ins.set_ide_subtype, None, None)

        with self.assertRaises(NotImplementedError):
            ins.version_short
        with self.assertRaises(NotImplementedError):
            ins.version_short = "hello"
        with self.assertRaises(NotImplementedError):
            ins.version_long
        with self.assertRaises(NotImplementedError):
            ins.version_long = "hello world!"

        with self.assertRaises(NotImplementedError):
            ins.environment_properties
        self.assertRaises(NotImplementedError,
                          ins.get_property_value, None)
        self.assertRaises(NotImplementedError,
                          ins.set_property_value, None, None)
        self.assertRaises(NotImplementedError,
                          ins.config_file_to_properties, self.TEXT_FILE)
        self.assertRaises(NotImplementedError,
                          ins.info_string)
        self.assertRaises(NotImplementedError,
                          ins.profile_info_string)

        self.assertRaises(NotImplementedError,
                          ins.find_empty_drive, None)
        self.assertRaises(NotImplementedError,
                          ins.find_device_location, None)

        ins.destroy()
        self.assertFalse(os.path.exists(ins.working_dir))