예제 #1
0
 def test_post_gc_status(self):
     cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
     conf = Config(cf)
     self.assertFalse(conf.post_gc_status)
     cf._insertKey("MISC|POST-GC-STATUS", "YES")
     conf = Config(cf)
     self.assertTrue(conf.post_gc_status)
예제 #2
0
 def test_no_default_run_post_script(self):
     cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
     conf = Config(cf)
     self.assertFalse(conf.default_run_post_script)
     cf._insertKey("MISC|DEFAULT-RUN-POST-CUST-SCRIPT", "NO")
     conf = Config(cf)
     self.assertFalse(conf.default_run_post_script)
예제 #3
0
 def test_user_data(self):
     cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
     conf = Config(cf)
     self.assertIsNone(conf.user_data_name)
     cf._insertKey("CLOUDINIT|USERDATA", "test-userdata")
     conf = Config(cf)
     self.assertEqual("test-userdata", conf.user_data_name)
예제 #4
0
 def test_custom_script(self):
     cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
     conf = Config(cf)
     self.assertIsNone(conf.custom_script_name)
     cf._insertKey("CUSTOM-SCRIPT|SCRIPT-NAME", "test-script")
     conf = Config(cf)
     self.assertEqual("test-script", conf.custom_script_name)
 def test_custom_script(self):
     cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
     conf = Config(cf)
     self.assertIsNone(conf.custom_script_name)
     cf._insertKey("CUSTOM-SCRIPT|SCRIPT-NAME", "test-script")
     conf = Config(cf)
     self.assertEqual("test-script", conf.custom_script_name)
예제 #6
0
    def test_config_password(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf._insertKey("PASSWORD|-PASS", "test-password")
        cf._insertKey("PASSWORD|RESET", "no")

        conf = Config(cf)
        self.assertEqual('test-password', conf.admin_password, "password")
        self.assertFalse(conf.reset_password, "do not reset password")
    def test_config_password(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf._insertKey("PASSWORD|-PASS", "test-password")
        cf._insertKey("PASSWORD|RESET", "no")

        conf = Config(cf)
        self.assertEqual('test-password', conf.admin_password, "password")
        self.assertFalse(conf.reset_password, "do not reset password")
예제 #8
0
    def test_set_gc_status(self):
        """
        This test is designed to verify the behavior of set_gc_status
        """
        # config is None, return None
        self.assertEqual(set_gc_status(None, 'Successful'), None)

        # post gc status is NO, return None
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
        conf = Config(cf)
        self.assertEqual(set_gc_status(conf, 'Successful'), None)

        # post gc status is YES, subp is called to execute command
        cf._insertKey("MISC|POST-GC-STATUS", "YES")
        conf = Config(cf)
        with mock.patch.object(util, 'subp',
                               return_value=('ok', b'')) as mockobj:
            self.assertEqual(set_gc_status(conf, 'Successful'), ('ok', b''))
            mockobj.assert_called_once_with(
                ['vmware-rpctool', 'info-set guestinfo.gc.status Successful'],
                rcs=[0])
    def test_utility_methods(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf.clear()

        self.assertEqual(0, len(cf), "clear size")

        cf._insertKey("  PASSWORD|-PASS ", "  foo  ")
        cf._insertKey("BAR", "   ")

        self.assertEqual(2, len(cf), "insert size")
        self.assertEqual('foo', cf["PASSWORD|-PASS"], "password")
        self.assertTrue("PASSWORD|-PASS" in cf, "hasPassword")
        self.assertFalse(cf.should_keep_current_value("PASSWORD|-PASS"),
                         "keepPassword")
        self.assertFalse(cf.should_remove_current_value("PASSWORD|-PASS"),
                         "removePassword")
        self.assertFalse("FOO" in cf, "hasFoo")
        self.assertTrue(cf.should_keep_current_value("FOO"), "keepFoo")
        self.assertFalse(cf.should_remove_current_value("FOO"), "removeFoo")
        self.assertTrue("BAR" in cf, "hasBar")
        self.assertFalse(cf.should_keep_current_value("BAR"), "keepBar")
        self.assertTrue(cf.should_remove_current_value("BAR"), "removeBar")
예제 #10
0
    def test_set_gc_status(self):
        """
        This test is designed to verify the behavior of set_gc_status
        """
        # config is None, return None
        self.assertEqual(set_gc_status(None, "Successful"), None)

        # post gc status is NO, return None
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")
        conf = Config(cf)
        self.assertEqual(set_gc_status(conf, "Successful"), None)

        # post gc status is YES, subp is called to execute command
        cf._insertKey("MISC|POST-GC-STATUS", "YES")
        conf = Config(cf)
        with mock.patch.object(subp,
                               "subp",
                               return_value=SubpResult("ok", b"")) as mockobj:
            self.assertEqual(set_gc_status(conf, "Successful"), ("ok", b""))
            mockobj.assert_called_once_with(
                ["vmware-rpctool", "info-set guestinfo.gc.status Successful"],
                rcs=[0],
            )
    def test_utility_methods(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf.clear()

        self.assertEqual(0, len(cf), "clear size")

        cf._insertKey("  PASSWORD|-PASS ", "  foo  ")
        cf._insertKey("BAR", "   ")

        self.assertEqual(2, len(cf), "insert size")
        self.assertEqual('foo', cf["PASSWORD|-PASS"], "password")
        self.assertTrue("PASSWORD|-PASS" in cf, "hasPassword")
        self.assertFalse(cf.should_keep_current_value("PASSWORD|-PASS"),
                         "keepPassword")
        self.assertFalse(cf.should_remove_current_value("PASSWORD|-PASS"),
                         "removePassword")
        self.assertFalse("FOO" in cf, "hasFoo")
        self.assertTrue(cf.should_keep_current_value("FOO"), "keepFoo")
        self.assertFalse(cf.should_remove_current_value("FOO"), "removeFoo")
        self.assertTrue("BAR" in cf, "hasBar")
        self.assertFalse(cf.should_keep_current_value("BAR"), "keepBar")
        self.assertTrue(cf.should_remove_current_value("BAR"), "removeBar")
예제 #12
0
    def test_config_reset_passwd(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf._insertKey("PASSWORD|-PASS", "test-password")
        cf._insertKey("PASSWORD|RESET", "random")

        conf = Config(cf)
        with self.assertRaises(ValueError):
            conf.reset_password()

        cf.clear()
        cf._insertKey("PASSWORD|RESET", "yes")
        self.assertEqual(1, len(cf), "insert size")

        conf = Config(cf)
        self.assertTrue(conf.reset_password, "reset password")
    def test_config_reset_passwd(self):
        cf = ConfigFile("tests/data/vmware/cust-dhcp-2nic.cfg")

        cf._insertKey("PASSWORD|-PASS", "test-password")
        cf._insertKey("PASSWORD|RESET", "random")

        conf = Config(cf)
        with self.assertRaises(ValueError):
            pw = conf.reset_password
            self.assertIsNone(pw)

        cf.clear()
        cf._insertKey("PASSWORD|RESET", "yes")
        self.assertEqual(1, len(cf), "insert size")

        conf = Config(cf)
        self.assertTrue(conf.reset_password, "reset password")