Esempio n. 1
0
    def test_70_contextualize_vm(self, test_connectivity):
        ctxt_agent = CtxtAgent(None)
        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
        ctxt_agent.LaunchAnsiblePlaybook.return_value = (MagicMock(), 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 = 'init'
        ctxt_agent.removeRequiretty = MagicMock()
        ctxt_agent.removeRequiretty.return_value = True

        res = ctxt_agent.contextualize_vm(self.gen_general_conf(),
                                          self.gen_vm_conf(["basic"]))
        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(["main", "front"]))
        expected_res = {'OK': True, 'front': True, 'main': True}
        self.assertEqual(res, expected_res)
Esempio n. 2
0
 def test_50_launch_ansible_thread(self, queue, ansible_thread):
     CtxtAgent.logger = self.logger
     vm = self.gen_vm_data()
     queue_mock = MagicMock()
     queue.return_value = queue_mock
     queue_mock.get.return_value = None, (0, []), None
     ansible_thread = CtxtAgent.LaunchAnsiblePlaybook(self.logger, "/tmp", "play.yml",
                                                      vm, 1, "/tmp/inv", "/tmp/pk.pem",
                                                      3, True, None)
     res = CtxtAgent.wait_thread(ansible_thread, "All was OK.")
     self.assertEqual(res, (True, []))