Пример #1
0
    def test_copy_playbooks(self, sftp_put_dir, sftp_chmod, test_connectivity,
                            execute):
        ctxt_agent = CtxtAgent("", "")
        ctxt_agent.logger = self.logger
        execute.return_value = "out", "err", 0

        general_conf_data = self.gen_general_conf()
        vm = self.gen_vm_data()
        lock = threading.Lock()
        errors = []
        ctxt_agent.copy_playbooks(vm, general_conf_data, errors, lock)
        self.assertEqual(errors, [])
Пример #2
0
    def test_launch_ansible_remote(self, sftp_put, execute):
        ctxt_agent = CtxtAgent("", "")
        ctxt_agent.logger = self.logger
        execute.return_value = ("pid", "", "")

        with open("/tmp/gen_data.json", "w+") as f:
            json.dump(self.gen_general_conf(), f)
        with open("/tmp/vm_data.json", "w+") as f:
            json.dump(self.gen_vm_conf(["basic"]), f)
        ctxt_agent.vm_conf_data_filename = "/tmp/gen_data.json"
        ctxt_agent.conf_data_filename = "/tmp/vm_data.json"

        vm = self.gen_vm_data()
        res = ctxt_agent.LaunchRemoteInstallAnsible(vm, None, False)
        self.assertEqual(res[1], "pid")
Пример #3
0
    def test_launch_ansible_thread(self, test_connectivity, queue,
                                   ansible_thread):
        ctxt_agent = CtxtAgent("", "/tmp/conf.dat")
        ctxt_agent.logger = self.logger
        vm = self.gen_vm_data()
        queue_mock = MagicMock()
        queue.return_value = queue_mock
        queue_mock.get.return_value = None, 0, None
        thread = ctxt_agent.LaunchAnsiblePlaybook(self.logger, "/tmp",
                                                  "play.yml", vm, 1,
                                                  "/tmp/inv", "/tmp/pk.pem", 3,
                                                  True, None)
        res = ctxt_agent.wait_thread(thread, self.gen_general_conf(), False)
        self.assertEqual(res, True)

        thread[0].is_alive.return_value = False
        res = ctxt_agent.wait_thread(thread, self.gen_general_conf(), True)
        self.assertEqual(res, True)
Пример #4
0
    def test_run(self, sftp_put):
        ctxt_agent = CtxtAgent("/tmp/gen_data.json", "/tmp/vm_data.json")
        ctxt_agent.logger = self.logger
        ctxt_agent.contextualize_vm = MagicMock()
        ctxt_agent.contextualize_vm.return_value = {
            'SSH_WAIT': True,
            'OK': True,
            'CHANGE_CREDS': True,
            'basic': True
        }

        with open("/tmp/gen_data.json", "w+") as f:
            json.dump(self.gen_general_conf(), f)
        with open("/tmp/vm_data.json", "w+") as f:
            json.dump(self.gen_vm_conf(["basic"]), f)

        res = ctxt_agent.run(0)
        self.assertTrue(res)

        open("/tmp/ctxt_agent.log", 'a').close()
        res = ctxt_agent.run(1)
        self.assertTrue(res)
Пример #5
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)
Пример #6
0
 def test_gen_facts_cache(self, ansible_thread):
     ctxt_agent = CtxtAgent("", "")
     ctxt_agent.logger = self.logger
     ctxt_agent.gen_facts_cache('/tmp', '', None)