Exemple #1
0
    def test_60_changeVMCredentials(self, winrm_session, execute,
                                    execute_timeout):
        CtxtAgent.logger = self.logger
        execute.return_value = "", "", 0
        execute_timeout.return_value = "", "", 0
        vm = self.gen_vm_data()
        res = CtxtAgent.changeVMCredentials(vm, None)
        self.assertTrue(res)

        vm = self.gen_vm_data()
        del vm['new_passwd']
        vm['new_public_key'] = "new_public_key"
        vm['new_private_key'] = "new_private_key"
        res = CtxtAgent.changeVMCredentials(vm, None)
        self.assertTrue(res)

        session = MagicMock()
        req = MagicMock
        req.status_code = 0
        session.run_cmd.return_value = req
        winrm_session.return_value = session
        vm = self.gen_vm_data("windows")
        res = CtxtAgent.changeVMCredentials(vm, None)
        self.assertTrue(res)
Exemple #2
0
    def test_contextualize_vm(self, from_private_key, sftp_put_dir, sftp_mkdir,
                              sftp_put, execute, test_connectivity):
        ctxt_agent = CtxtAgent("/tmp/gconf.dat", "/tmp/conf.dat")
        ctxt_agent.logger = self.logger
        ctxt_agent.changeVMCredentials = MagicMock()
        ctxt_agent.changeVMCredentials.return_value = True
        ctxt_agent.LaunchAnsiblePlaybook = MagicMock()
        queue = MagicMock()
        queue.get.return_value = None, 0, None
        thread = MagicMock()
        thread.is_alive.return_value = False
        ctxt_agent.LaunchAnsiblePlaybook.return_value = (thread, queue)
        ctxt_agent.wait_winrm_access = MagicMock()
        ctxt_agent.wait_winrm_access.return_value = True
        ctxt_agent.wait_ssh_access = MagicMock()
        ctxt_agent.wait_ssh_access.return_value = True
        ctxt_agent.removeRequiretty = MagicMock()
        ctxt_agent.removeRequiretty.return_value = True
        execute.return_value = "1", 1, 1

        ctxt_vm = None
        for vm in self.gen_general_conf()['vms']:
            if vm['id'] == self.gen_vm_conf(["basic"])['id']:
                ctxt_vm = vm

        with open("/tmp/ctxt_agent.out", 'w+') as f:
            f.write('{"OK": true}')
        res = ctxt_agent.contextualize_vm(self.gen_general_conf(),
                                          self.gen_vm_conf(["basic"]), ctxt_vm,
                                          0)
        expected_res = {
            'SSH_WAIT': True,
            'OK': True,
            'CHANGE_CREDS': True,
            'basic': True
        }
        self.assertEqual(res, expected_res)

        res = ctxt_agent.contextualize_vm(self.gen_general_conf(),
                                          self.gen_vm_conf(["basic"]), ctxt_vm,
                                          1)
        expected_res = {'SSH_WAIT': True, 'OK': True, 'basic': True}
        self.assertEqual(res, expected_res)

        ctxt_vm = None
        for vm in self.gen_general_conf()['vms']:
            if vm['id'] == self.gen_vm_conf(["main", "front"])['id']:
                ctxt_vm = vm

        res = ctxt_agent.contextualize_vm(self.gen_general_conf(),
                                          self.gen_vm_conf(["main", "front"]),
                                          ctxt_vm, 0)
        expected_res = {'OK': True, 'front': True, 'main': True}
        self.assertEqual(res, expected_res)

        res = ctxt_agent.contextualize_vm(self.gen_general_conf(),
                                          self.gen_vm_conf(["main", "front"]),
                                          ctxt_vm, 1)
        expected_res = {'OK': True, 'front': True, 'main': True}
        self.assertEqual(res, expected_res)

        res = ctxt_agent.contextualize_vm(
            self.gen_general_conf(), self.gen_vm_conf(["copy_facts_cache"]),
            ctxt_vm, 0)
        expected_res = {'OK': True, 'copy_facts_cache': True}
        self.assertEqual(res, expected_res)