Ejemplo n.º 1
0
    def test_get_ctxt_output(self, mkdtemp):
        ssh = MagicMock()
        tmp_dir = "%s/test_get_ctxt" % tempfile.gettempdir()
        mkdtemp.return_value = tmp_dir
        os.mkdir(tmp_dir)
        with open('%s/ctxt_agent.out' % tmp_dir, 'w+') as f:
            f.write('{"OK": true, "CHANGE_CREDS": true}')

        radl_data = """
            system test (
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.credentials.new.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        inf = MagicMock()
        inf.id = "1"
        vm = VirtualMachine(inf, "1", None, radl, radl)
        cont_out = vm.get_ctxt_output("", ssh, delete=True)
        self.assertEqual(
            cont_out, "Contextualization agent output processed successfully")
        self.assertEqual(vm.info.systems[0].getCredentialValues(),
                         ('user', 'newpass', None, None))

        os.mkdir(tmp_dir)
        ssh.sftp_get.side_effect = IOError()
        with open('%s/stderr' % tmp_dir, 'w+') as f:
            f.write('stderr')
        with open('%s/stdout' % tmp_dir, 'w+') as f:
            f.write('stdout')
        cont_out = vm.get_ctxt_output("", ssh, delete=True)
        self.assertEqual(
            cont_out,
            "Error getting contextualization agent output /ctxt_agent.out:"
            "  No such file.\nstdout\nstderr\n")
Ejemplo n.º 2
0
    def test_get_ctxt_output(self, mkdtemp, get_ssh_ansible_master):
        ssh = MagicMock()
        get_ssh_ansible_master.return_value = ssh
        mkdtemp.return_value = "/tmp/test_get_ctxt"
        os.mkdir("/tmp/test_get_ctxt")
        with open('/tmp/test_get_ctxt/ctxt_agent.out', 'w+') as f:
            f.write('{"OK": true, "CHANGE_CREDS": true}')

        radl_data = """
            system test (
            disk.0.os.credentials.username = '******' and
            disk.0.os.credentials.password = '******' and
            disk.0.os.credentials.new.password = '******'
            )"""
        radl = radl_parse.parse_radl(radl_data)
        inf = MagicMock()
        inf.id = "1"
        vm = VirtualMachine(inf, "1", None, radl, radl)
        cont_out = vm.get_ctxt_output("", delete=True)
        self.assertEqual(cont_out, "Contextualization agent output processed successfully")
        self.assertEqual(vm.info.systems[0].getCredentialValues(), ('user', 'newpass', None, None))