2019-04-04 08:10:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import mock
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
from pungi.runroot import Runroot
|
|
|
|
from tests import helpers
|
|
|
|
|
|
|
|
|
|
|
|
class TestRunrootOpenSSH(helpers.PungiTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TestRunrootOpenSSH, self).setUp()
|
|
|
|
self.compose = helpers.DummyCompose(self.topdir, {
|
|
|
|
"runroot": True,
|
|
|
|
"runroot_method": "openssh",
|
|
|
|
"runroot_ssh_user": "root",
|
|
|
|
"runroot_ssh_hostnames": {
|
|
|
|
"x86_64": "localhost"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
self.runroot = Runroot(self.compose)
|
|
|
|
|
|
|
|
def test_get_runroot_method(self):
|
|
|
|
method = self.runroot.get_runroot_method()
|
|
|
|
self.assertEqual(method, "openssh")
|
|
|
|
|
2019-04-11 10:26:29 +00:00
|
|
|
def _ssh_call(self, cmd):
|
|
|
|
"""
|
|
|
|
Helper method returning default SSH mock.call with given command `cmd`.
|
|
|
|
"""
|
|
|
|
return mock.call(
|
|
|
|
['ssh', '-oBatchMode=yes', '-n', '-l', 'root', 'localhost', cmd],
|
|
|
|
logfile='/foo/runroot.log',
|
|
|
|
show_cmd=True,
|
|
|
|
)
|
|
|
|
|
2019-04-04 08:10:48 +00:00
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_run(self, run):
|
2019-04-11 10:26:29 +00:00
|
|
|
run.return_value = (0, "dummy output\n")
|
2019-04-04 08:10:48 +00:00
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64")
|
|
|
|
run.assert_has_calls([
|
2019-04-11 10:26:29 +00:00
|
|
|
self._ssh_call('df -h'),
|
|
|
|
self._ssh_call("rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"),
|
2019-04-04 08:10:48 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_get_buildroot_rpms(self, run):
|
|
|
|
# Run the runroot task at first.
|
|
|
|
run.return_value = (0, "foo-1-1.fc29.noarch\nbar-1-1.fc29.noarch\n")
|
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64")
|
|
|
|
|
|
|
|
rpms = self.runroot.get_buildroot_rpms()
|
|
|
|
self.assertEqual(
|
|
|
|
set(rpms), set(["foo-1-1.fc29.noarch", "bar-1-1.fc29.noarch"]))
|
2019-04-11 10:26:29 +00:00
|
|
|
|
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_run_templates(self, run):
|
|
|
|
self.compose.conf["runroot_ssh_init_command"] = "/usr/sbin/init_runroot"
|
|
|
|
self.compose.conf["runroot_ssh_install_packages_template"] = \
|
|
|
|
"install {runroot_key} {packages}"
|
|
|
|
self.compose.conf["runroot_ssh_run_template"] = "run {runroot_key} {command}"
|
|
|
|
|
|
|
|
run.return_value = (0, "key\n")
|
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64",
|
|
|
|
packages=["lorax", "automake"])
|
|
|
|
run.assert_has_calls([
|
|
|
|
self._ssh_call('/usr/sbin/init_runroot'),
|
|
|
|
self._ssh_call('install key lorax automake'),
|
|
|
|
self._ssh_call('run key df -h'),
|
|
|
|
self._ssh_call("run key rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"),
|
|
|
|
])
|
|
|
|
|
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_run_templates_no_init(self, run):
|
|
|
|
self.compose.conf["runroot_ssh_install_packages_template"] = \
|
|
|
|
"install {packages}"
|
|
|
|
self.compose.conf["runroot_ssh_run_template"] = "run {command}"
|
|
|
|
|
|
|
|
run.return_value = (0, "key\n")
|
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64",
|
|
|
|
packages=["lorax", "automake"])
|
|
|
|
run.assert_has_calls([
|
|
|
|
self._ssh_call('install lorax automake'),
|
|
|
|
self._ssh_call('run df -h'),
|
|
|
|
self._ssh_call("run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"),
|
|
|
|
])
|
|
|
|
|
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_run_templates_no_packages(self, run):
|
|
|
|
self.compose.conf["runroot_ssh_install_packages_template"] = \
|
|
|
|
"install {packages}"
|
|
|
|
self.compose.conf["runroot_ssh_run_template"] = "run {command}"
|
|
|
|
|
|
|
|
run.return_value = (0, "key\n")
|
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64")
|
|
|
|
run.assert_has_calls([
|
|
|
|
self._ssh_call('run df -h'),
|
|
|
|
self._ssh_call("run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"),
|
|
|
|
])
|
|
|
|
|
|
|
|
@mock.patch("pungi.runroot.run")
|
|
|
|
def test_run_templates_no_install_packages(self, run):
|
|
|
|
self.compose.conf["runroot_ssh_run_template"] = "run {command}"
|
|
|
|
|
|
|
|
run.return_value = (0, "key\n")
|
|
|
|
self.runroot.run("df -h", log_file="/foo/runroot.log", arch="x86_64",
|
|
|
|
packages=["lorax", "automake"])
|
|
|
|
run.assert_has_calls([
|
|
|
|
self._ssh_call('run df -h'),
|
|
|
|
self._ssh_call("run rpm -qa --qf='%{name}-%{version}-%{release}.%{arch}\n'"),
|
|
|
|
])
|