예제 #1
0
파일: test_ui.py 프로젝트: stephen11ma/cot
    def test_stub_apis(self):
        """Test stub APIs that subclasses should override."""
        ins = UI()
        self.assertEqual("subcommand --foo\nsubcommand --bar",
                         ins.fill_usage("subcommand", ["--foo", "--bar"]))

        self.assertRaises(NotImplementedError, ins.fill_examples,
                          [("foo", "bar"), ("baz", "bat")])

        self.assertRaises(NotImplementedError, ins.get_password, "user",
                          "host")
예제 #2
0
    def test_stub_apis(self):
        """Test stub APIs that subclasses should override."""
        ins = UI()
        self.assertEqual("subcommand --foo\nsubcommand --bar",
                         ins.fill_usage("subcommand", ["--foo", "--bar"]))

        self.assertRaises(NotImplementedError,
                          ins.fill_examples,
                          [("foo", "bar"), ("baz", "bat")])

        self.assertRaises(NotImplementedError,
                          ins.get_password, "user", "host")
예제 #3
0
 def test_call_no_install(self):
     """If not installed, and user declines, raise HelperNotFoundError."""
     _ui = Helper.USER_INTERFACE
     Helper.USER_INTERFACE = UI()
     Helper.USER_INTERFACE.default_confirm_response = False
     try:
         self.assertRaises(HelperNotFoundError,
                           self.helper.call, ["Hello!"])
     finally:
         Helper.USER_INTERFACE = _ui
예제 #4
0
파일: test_ui.py 프로젝트: stephen11ma/cot
    def test_apis_without_force(self):
        """Test confirm(), confirm_or_die(), etc. without --force."""
        ins = UI()

        self.assertTrue(ins.confirm("prompt"))
        ins.confirm_or_die("prompt")

        ins.default_confirm_response = False
        self.assertFalse(ins.confirm("prompt"))
        self.assertRaises(SystemExit, ins.confirm_or_die, "prompt")

        self.assertEqual("hello", ins.get_input("Prompt:", "hello"))
예제 #5
0
파일: test_ui.py 프로젝트: stephen11ma/cot
    def test_apis_with_force(self):
        """Test confirm(), confirm_or_die(), etc. with --force."""
        ins = UI(force=True)

        self.assertTrue(ins.confirm("prompt"))
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.confirm_or_die("prompt")
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.default_confirm_response = False
        # With --force, the default_confirm_response doesn't apply
        self.assertTrue(ins.confirm("prompt"))
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.confirm_or_die("prompt")
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        self.assertEqual("hello", ins.get_input("Prompt:", "hello"))
        self.assertLogged(levelname="WARNING",
                          msg="Automatically entering",
                          args=('hello', 'Prompt:'))
예제 #6
0
    def test_apis_without_force(self):
        """Test confirm(), confirm_or_die(), etc. without --force."""
        ins = UI()

        self.assertTrue(ins.confirm("prompt"))
        ins.confirm_or_die("prompt")

        ins.default_confirm_response = False
        self.assertFalse(ins.confirm("prompt"))
        self.assertRaises(SystemExit, ins.confirm_or_die, "prompt")

        self.assertEqual("hello", ins.get_input("Prompt:", "hello"))
예제 #7
0
    def test_apis_with_force(self):
        """Test confirm(), confirm_or_die(), etc. with --force."""
        ins = UI(force=True)

        self.assertTrue(ins.confirm("prompt"))
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.confirm_or_die("prompt")
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.default_confirm_response = False
        # With --force, the default_confirm_response doesn't apply
        self.assertTrue(ins.confirm("prompt"))
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        ins.confirm_or_die("prompt")
        self.assertLogged(levelname="WARNING", msg="Automatically agreeing")

        self.assertEqual("hello", ins.get_input("Prompt:", "hello"))
        self.assertLogged(levelname="WARNING", msg="Automatically entering",
                          args=('hello', 'Prompt:'))
예제 #8
0
    def test_inject_config_iso_multiple_drives(self):
        """Inject config file on an ISO when multiple empty drives exist."""
        temp_ovf = os.path.join(self.temp_dir, "intermediate.ovf")

        # Remove the existing ISO from our input_ovf:
        remover = COTRemoveFile(UI())
        remover.package = self.input_ovf
        remover.output = temp_ovf
        remover.file_path = "input.iso"
        remover.run()
        remover.finished()
        remover.destroy()

        # Now we have two empty drives.
        self.command.package = temp_ovf
        self.command.config_file = self.config_file
        self.command.run()
        self.assertLogged(**self.OVERWRITING_DISK_ITEM)
        self.command.finished()
        config_iso = os.path.join(self.temp_dir, 'config.iso')
        self.check_diff("""
     <ovf:File ovf:href="input.vmdk" ovf:id="file1" ovf:size="{vmdk_size}" />
-    <ovf:File ovf:href="input.iso" ovf:id="file2" ovf:size="{iso_size}" />
     <ovf:File ovf:href="sample_cfg.txt" ovf:id="textfile" \
ovf:size="{cfg_size}" />
+    <ovf:File ovf:href="config.iso" ovf:id="config.iso" \
ovf:size="{config_size}" />
   </ovf:References>
...
         <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
+        <rasd:Description>Configuration disk</rasd:Description>
         <rasd:ElementName>CD-ROM 1</rasd:ElementName>
-        <rasd:HostResource>ovf:/file/file2</rasd:HostResource>
+        <rasd:HostResource>ovf:/file/config.iso</rasd:HostResource>
         <rasd:InstanceID>7</rasd:InstanceID>""".format(
            vmdk_size=self.FILE_SIZE['input.vmdk'],
            iso_size=self.FILE_SIZE['input.iso'],
            cfg_size=self.FILE_SIZE['sample_cfg.txt'],
            config_size=os.path.getsize(config_iso)))
        if helpers['isoinfo']:
            # The sample_cfg.text should be renamed to the platform-specific
            # file name for bootstrap config - in this case, config.txt
            self.assertEqual(
                DiskRepresentation.from_file(config_iso).files, ["config.txt"])
        else:
            logger.info("isoinfo not available, not checking disk contents")
예제 #9
0
    def test_add_file_then_change_to_disk(self):
        """Add a disk as a file, then make it a proper disk."""
        self.command.package = self.minimal_ovf
        intermediate_ovf = os.path.join(self.temp_dir, "mid.ovf")
        self.command.output = intermediate_ovf
        self.command.file = self.blank_vmdk
        self.command.file_id = "mydisk"
        self.command.run()
        self.command.finished()
        self.check_diff(file1=self.minimal_ovf,
                        file2=intermediate_ovf,
                        expected="""
 <ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
-  <ovf:References />
+  <ovf:References>
+    <ovf:File ovf:href="blank.vmdk" ovf:id="mydisk" ovf:size="{0}" />
+  </ovf:References>
   <ovf:VirtualSystem ovf:id="x">
""".format(self.FILE_SIZE['blank.vmdk']))

        from COT.commands.add_disk import COTAddDisk
        add_disk = COTAddDisk(UI())
        add_disk.package = intermediate_ovf
        add_disk.output = self.temp_file
        add_disk.disk_image = self.blank_vmdk
        add_disk.file_id = "mydisk"
        add_disk.run()
        self.assertLogged(**self.DRIVE_TYPE_GUESSED_HARDDISK)
        self.assertLogged(**self.CONTROLLER_TYPE_GUESSED_IDE)
        self.assertLogged(**self.OVERWRITING_FILE)
        self.assertLogged(**self.ADDRESS_ON_PARENT_NOT_SPECIFIED)
        add_disk.finished()
        add_disk.destroy()
        self.check_diff(file1=intermediate_ovf,
                        expected="""
 <?xml version='1.0' encoding='utf-8'?>
-<ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1">
+<ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" \
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/\
CIM_ResourceAllocationSettingData">
   <ovf:References>
...
   </ovf:References>
+  <ovf:DiskSection>
+    <ovf:Info>Virtual disk information</ovf:Info>
+    <ovf:Disk ovf:capacity="512" ovf:capacityAllocationUnits="byte * 2^20" \
ovf:diskId="mydisk" ovf:fileRef="mydisk" ovf:format="http://www.vmware.com/\
interfaces/specifications/vmdk.html#streamOptimized" />
+  </ovf:DiskSection>
   <ovf:VirtualSystem ovf:id="x">
...
       <ovf:Info />
+      <ovf:Item>
+        <rasd:Address>0</rasd:Address>
+        <rasd:Description>IDE Controller 0</rasd:Description>
+        <rasd:ElementName>IDE Controller</rasd:ElementName>
+        <rasd:InstanceID>1</rasd:InstanceID>
+        <rasd:ResourceType>5</rasd:ResourceType>
+      </ovf:Item>
+      <ovf:Item>
+        <rasd:AddressOnParent>0</rasd:AddressOnParent>
+        <rasd:ElementName>Hard Disk Drive</rasd:ElementName>
+        <rasd:HostResource>ovf:/disk/mydisk</rasd:HostResource>
+        <rasd:InstanceID>2</rasd:InstanceID>
+        <rasd:Parent>1</rasd:Parent>
+        <rasd:ResourceType>17</rasd:ResourceType>
+      </ovf:Item>
     </ovf:VirtualHardwareSection>
""")
예제 #10
0
 def setUp(self):
     """Test case setup function called automatically before each test."""
     super(CommandTestCase, self).setUp()
     self.command = self.command_class(UI())
     if isinstance(self.command, ReadWriteCommand):
         self.command._output = self.temp_file