Exemplo n.º 1
0
    def test_tar_links(self):
        """Check that OVA dereferences symlinks and hard links."""
        self.staging_dir = tempfile.mkdtemp(prefix="cot_ut_ovfio_stage")
        shutil.copy(self.input_ovf, self.staging_dir)
        # Hardlink self.input_vmdk to the staging dir
        os.link(self.input_vmdk, os.path.join(self.staging_dir, 'input.vmdk'))
        # Symlink self.input_iso to the staging dir
        os.symlink(self.input_iso, os.path.join(self.staging_dir, 'input.iso'))
        shutil.copy(self.sample_cfg, self.staging_dir)
        ovf = OVF(os.path.join(self.staging_dir, 'input.ovf'),
                  os.path.join(self.temp_dir, 'input.ova'))
        ovf.write()
        ovf.destroy()

        with tarfile.open(os.path.join(self.temp_dir, 'input.ova'),
                          'r') as tarf:
            try:
                vmdk = tarf.getmember('input.vmdk')
                self.assertTrue(vmdk.isfile(),
                                "hardlink was not added as a regular file")
                self.assertFalse(vmdk.islnk())
                iso = tarf.getmember('input.iso')
                self.assertTrue(iso.isfile(),
                                "symlink was not added as a regular file")
                self.assertFalse(iso.issym())
            except KeyError as exc:
                self.fail("KeyError: {0}\n Tarfile members = {1}".format(
                    exc, tarf.getnames()))
Exemplo n.º 2
0
    def test_set_property_no_modification(self):
        """Test various operations that should do nothing."""
        ovf = OVF(self.input_ovf, self.temp_file)
        # InstanceID 4, IDE controller
        item = ovf.hardware.item_dict['4']

        # set global value to empty for a property with no value
        self.assertFalse(item.modified)
        item.set_property(ovf.RESOURCE_SUB_TYPE, '')
        self.assertFalse(item.modified)

        # set per-profile value to empty for a property with no value
        item.set_property(ovf.RESOURCE_SUB_TYPE, '', ['2CPU-2GB-1NIC'])
        self.assertFalse(item.modified)

        # set global value to the same as existing global value
        item.set_property(ovf.ELEMENT_NAME, "VirtualIDEController 1")
        self.assertFalse(item.modified)

        # set per-profile value to the same as existing global value
        item.set_property(ovf.ELEMENT_NAME, "VirtualIDEController 1",
                          ['2CPU-2GB-1NIC'])
        self.assertFalse(item.modified)

        ovf.write()
        ovf.destroy()
        self.check_diff("")
Exemplo n.º 3
0
    def test_set_property_no_modification(self):
        """Test various operations that should do nothing."""
        ovf = OVF(self.input_ovf, self.temp_file)
        # InstanceID 4, IDE controller
        item = ovf.hardware.item_dict['4']

        # set global value to empty for a property with no value
        self.assertFalse(item.modified)
        item.set_property(ovf.RESOURCE_SUB_TYPE, '')
        self.assertFalse(item.modified)

        # set per-profile value to empty for a property with no value
        item.set_property(ovf.RESOURCE_SUB_TYPE, '', ['2CPU-2GB-1NIC'])
        self.assertFalse(item.modified)

        # set global value to the same as existing global value
        item.set_property(ovf.ELEMENT_NAME, "VirtualIDEController 1")
        self.assertFalse(item.modified)

        # set per-profile value to the same as existing global value
        item.set_property(ovf.ELEMENT_NAME, "VirtualIDEController 1",
                          ['2CPU-2GB-1NIC'])
        self.assertFalse(item.modified)

        ovf.write()
        ovf.destroy()
        self.check_diff("")
Exemplo n.º 4
0
    def test_tar_untar(self):
        """Output OVF to OVA and vice versa."""
        # Read OVF and write to OVA
        ovf = OVF(self.input_ovf, os.path.join(self.temp_dir, "temp.ova"))
        ovf.write()
        ovf.destroy()

        # Read OVA and overwrite itself
        # Issue #66 resulted from the two strings not being identical
        # So mix relative and absolute paths:
        os.chdir(self.temp_dir)
        ova = OVF("temp.ova", os.path.join(self.temp_dir, "temp.ova"))
        ova.write()
        ova.destroy()

        # Another permutation of issue #66 - output file is a
        # symlink to input file
        os.symlink("temp.ova", "symlink.ova")
        ova = OVF("temp.ova", "symlink.ova")
        ova.write()
        ova.destroy()

        # A third permutation - output file is hardlink to input
        os.link("temp.ova", "hardlink.ova")
        ova = OVF("temp.ova", "hardlink.ova")
        ova.write()
        ova.destroy()

        # Read OVA and write to OVF
        ovf2 = OVF(os.path.join(self.temp_dir, "temp.ova"),
                   os.path.join(self.temp_dir, "input.ovf"))
        ovf2.write()
        ovf2.destroy()

        # Make sure everything propagated over successfully
        input_dir = os.path.dirname(self.input_ovf)
        for ext in ['.ovf', '.mf', '.iso', '.vmdk']:
            if ext == '.mf' or ext == '.ovf':
                self.check_diff("", os.path.join(input_dir, "input" + ext),
                                os.path.join(self.temp_dir, "input" + ext))
            else:
                self.assertTrue(
                    filecmp.cmp(os.path.join(input_dir, "input" + ext),
                                os.path.join(self.temp_dir, "input" + ext)),
                    "{0} file changed after OVF->OVA->OVF conversion".format(
                        ext))
Exemplo n.º 5
0
    def test_set_property(self):
        """Test cases for set_property() and related methods."""
        ovf = OVF(self.input_ovf, self.temp_file)
        # InstanceID 1, 'CPU' - entries for 'default' plus two other profiles
        item = ovf.hardware.item_dict['1']

        self.assertTrue(item.has_profile(None))
        self.assertTrue(item.has_profile("2CPU-2GB-1NIC"))
        self.assertTrue(item.has_profile("4CPU-4GB-3NIC"))
        # implied by default profile
        self.assertTrue(item.has_profile("1CPU-1GB-1NIC"))
        # nonexistent profile
        self.assertFalse(item.has_profile("nonexistent"))

        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY, ['1CPU-1GB-1NIC']), '1')
        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY, ['2CPU-2GB-1NIC']), '2')
        # value differs between profiles, so get_value returns None
        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY,
                           ['1CPU-1GB-1NIC', '2CPU-2GB-1NIC']), None)
        self.assertFalse(item.modified)

        # Set profile 1 to same as default (this is a no-op)
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["1CPU-1GB-1NIC"])
        self.assertFalse(item.modified)
        ovf.write()
        self.check_diff("")

        # Change profile 1 to same as profile 2
        item.set_property(ovf.VIRTUAL_QUANTITY, '2', ["1CPU-1GB-1NIC"])
        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY,
                           ['1CPU-1GB-1NIC', '2CPU-2GB-1NIC']), '2')
        self.assertTrue(item.modified)
        ovf.write()
        self.check_diff("""
       </ovf:Item>
-      <ovf:Item ovf:configuration="2CPU-2GB-1NIC">
+      <ovf:Item ovf:configuration="1CPU-1GB-1NIC 2CPU-2GB-1NIC">
         <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
""")

        # Change profile 1 back under default
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["1CPU-1GB-1NIC"])
        self.assertTrue(item.modified)
        ovf.write()
        self.check_diff("")

        # Change profile 2 to fall under default
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["2CPU-2GB-1NIC"])
        self.assertTrue(item.modified)
        self.assertTrue(item.has_profile(None))
        self.assertTrue(item.has_profile("4CPU-4GB-3NIC"))
        # implied by default profile
        self.assertTrue(item.has_profile("1CPU-1GB-1NIC"))
        self.assertTrue(item.has_profile("2CPU-2GB-1NIC"))
        # nonexistent profile
        self.assertFalse(item.has_profile("nonexistent"))

        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY,
                           ['1CPU-1GB-1NIC', '2CPU-2GB-1NIC']), '1')
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY, [None]), '1')
        self.assertEqual(
            item.get_value(ovf.VIRTUAL_QUANTITY,
                           [None, '1CPU-1GB-1NIC', '2CPU-2GB-1NIC']), '1')
        # disjoint sets
        self.assertEqual(
            item.get_value(
                ovf.VIRTUAL_QUANTITY,
                [None, '1CPU-1GB-1NIC', '2CPU-2GB-1NIC', '4CPU-4GB-3NIC']),
            None)

        ovf.write()
        self.check_diff("""
       </ovf:Item>
-      <ovf:Item ovf:configuration="2CPU-2GB-1NIC">
-        <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
-        <rasd:Description>Number of Virtual CPUs</rasd:Description>
-        <rasd:ElementName>2 virtual CPU(s)</rasd:ElementName>
-        <rasd:InstanceID>1</rasd:InstanceID>
-        <rasd:ResourceType>3</rasd:ResourceType>
-        <rasd:VirtualQuantity>2</rasd:VirtualQuantity>
-        <vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket>
-      </ovf:Item>
       <ovf:Item ovf:configuration="4CPU-4GB-3NIC">
""")
        ovf.destroy()
Exemplo n.º 6
0
    def test_set_property(self):
        """Test cases for set_property() and related methods."""
        ovf = OVF(self.input_ovf, self.temp_file)
        # InstanceID 1, 'CPU' - entries for 'default' plus two other profiles
        item = ovf.hardware.item_dict['1']

        self.assertTrue(item.has_profile(None))
        self.assertTrue(item.has_profile("2CPU-2GB-1NIC"))
        self.assertTrue(item.has_profile("4CPU-4GB-3NIC"))
        # implied by default profile
        self.assertTrue(item.has_profile("1CPU-1GB-1NIC"))
        # nonexistent profile
        self.assertFalse(item.has_profile("nonexistent"))

        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        ['1CPU-1GB-1NIC']),
                         '1')
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        ['2CPU-2GB-1NIC']),
                         '2')
        # value differs between profiles, so get_value returns None
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        ['1CPU-1GB-1NIC', '2CPU-2GB-1NIC']),
                         None)
        self.assertFalse(item.modified)

        # Set profile 1 to same as default (this is a no-op)
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["1CPU-1GB-1NIC"])
        self.assertFalse(item.modified)
        ovf.write()
        self.check_diff("")

        # Change profile 1 to same as profile 2
        item.set_property(ovf.VIRTUAL_QUANTITY, '2', ["1CPU-1GB-1NIC"])
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        ['1CPU-1GB-1NIC', '2CPU-2GB-1NIC']),
                         '2')
        self.assertTrue(item.modified)
        ovf.write()
        self.check_diff("""
       </ovf:Item>
-      <ovf:Item ovf:configuration="2CPU-2GB-1NIC">
+      <ovf:Item ovf:configuration="1CPU-1GB-1NIC 2CPU-2GB-1NIC">
         <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
""")

        # Change profile 1 back under default
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["1CPU-1GB-1NIC"])
        self.assertTrue(item.modified)
        ovf.write()
        self.check_diff("")

        # Change profile 2 to fall under default
        item.set_property(ovf.VIRTUAL_QUANTITY, '1', ["2CPU-2GB-1NIC"])
        self.assertTrue(item.modified)
        self.assertTrue(item.has_profile(None))
        self.assertTrue(item.has_profile("4CPU-4GB-3NIC"))
        # implied by default profile
        self.assertTrue(item.has_profile("1CPU-1GB-1NIC"))
        self.assertTrue(item.has_profile("2CPU-2GB-1NIC"))
        # nonexistent profile
        self.assertFalse(item.has_profile("nonexistent"))

        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        ['1CPU-1GB-1NIC',
                                         '2CPU-2GB-1NIC']),
                         '1')
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY, [None]),
                         '1')
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        [None, '1CPU-1GB-1NIC',
                                         '2CPU-2GB-1NIC']),
                         '1')
        # disjoint sets
        self.assertEqual(item.get_value(ovf.VIRTUAL_QUANTITY,
                                        [None, '1CPU-1GB-1NIC',
                                         '2CPU-2GB-1NIC', '4CPU-4GB-3NIC']),
                         None)

        ovf.write()
        self.check_diff("""
       </ovf:Item>
-      <ovf:Item ovf:configuration="2CPU-2GB-1NIC">
-        <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
-        <rasd:Description>Number of Virtual CPUs</rasd:Description>
-        <rasd:ElementName>2 virtual CPU(s)</rasd:ElementName>
-        <rasd:InstanceID>1</rasd:InstanceID>
-        <rasd:ResourceType>3</rasd:ResourceType>
-        <rasd:VirtualQuantity>2</rasd:VirtualQuantity>
-        <vmw:CoresPerSocket ovf:required="false">1</vmw:CoresPerSocket>
-      </ovf:Item>
       <ovf:Item ovf:configuration="4CPU-4GB-3NIC">
""")
        ovf.destroy()