|
@@ -42,7 +42,7 @@ class TestBootstrap(TestCase):
|
|
|
|
|
|
def test_getRemoteName(self):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
- "setupAgentFile", "ambariServer", "centos6", None, "8440")
|
|
|
+ "setupAgentFile", "ambariServer", "centos6", None, "8440", "root")
|
|
|
res = bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
utime1 = 1234
|
|
|
utime2 = 12345
|
|
@@ -65,7 +65,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getAmbariPort(self):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
self.assertEquals(bootstrap_obj.getAmbariPort(),"8440")
|
|
|
shared_state.server_port = None
|
|
@@ -81,11 +81,11 @@ class TestBootstrap(TestCase):
|
|
|
@patch("os.path.realpath")
|
|
|
def test_bootstrap_main(self, dirname_mock, realpath_mock, run_mock, exit_mock, stderr_mock, subprocess_Popen_mock):
|
|
|
bootstrap.main(["bootstrap.py", "hostname,hostname2", "/tmp/bootstrap", "root", "sshkey_file", "setupAgent.py", "ambariServer", \
|
|
|
- "centos6", "1.1.1", "8440", "passwordfile"])
|
|
|
+ "centos6", "1.1.1", "8440", "root", "passwordfile"])
|
|
|
self.assertTrue(run_mock.called)
|
|
|
run_mock.reset_mock()
|
|
|
bootstrap.main(["bootstrap.py", "hostname,hostname2", "/tmp/bootstrap", "root", "sshkey_file", "setupAgent.py", "ambariServer", \
|
|
|
- "centos6", "1.1.1", "8440", None])
|
|
|
+ "centos6", "1.1.1", "8440", "root", None])
|
|
|
self.assertTrue(run_mock.called)
|
|
|
run_mock.reset_mock()
|
|
|
def side_effect(retcode):
|
|
@@ -104,21 +104,21 @@ class TestBootstrap(TestCase):
|
|
|
def test_getRunSetupWithPasswordCommand(self, environ_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
environ_mock.__getitem__.return_value = "TEST_PASSPHRASE"
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
utime = 1234
|
|
|
bootstrap_obj.getUtime = MagicMock(return_value=utime)
|
|
|
ret = bootstrap_obj.getRunSetupWithPasswordCommand("hostname")
|
|
|
expected = "sudo -S python /var/lib/ambari-agent/data/tmp/setupAgent{0}.py hostname TEST_PASSPHRASE " \
|
|
|
- "ambariServer 8440 < /var/lib/ambari-agent/data/tmp/host_pass{0}".format(utime)
|
|
|
+ "ambariServer root 8440 < /var/lib/ambari-agent/data/tmp/host_pass{0}".format(utime)
|
|
|
self.assertEquals(ret, expected)
|
|
|
|
|
|
|
|
|
def test_generateRandomFileName(self):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
self.assertTrue(bootstrap_obj.generateRandomFileName(None) == bootstrap_obj.getUtime())
|
|
|
|
|
@@ -128,7 +128,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_is_suse(self, open_mock, isfile_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
isfile_mock.return_value = True
|
|
|
f = open_mock.return_value
|
|
@@ -140,7 +140,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getRepoDir(self, is_suse_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
# Suse
|
|
|
is_suse_mock.return_value = True
|
|
@@ -154,7 +154,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getSetupScript(self):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
self.assertEquals(bootstrap_obj.shared_state.script_dir, "scriptDir")
|
|
|
|
|
@@ -164,7 +164,7 @@ class TestBootstrap(TestCase):
|
|
|
version = "1.1.1"
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- version, "8440")
|
|
|
+ version, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
runSetupCommand = bootstrap_obj.getRunSetupCommand("hostname")
|
|
|
self.assertTrue(runSetupCommand.endswith(version + " 8440"))
|
|
@@ -175,7 +175,7 @@ class TestBootstrap(TestCase):
|
|
|
version = None
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- version, "8440")
|
|
|
+ version, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
runSetupCommand = bootstrap_obj.getRunSetupCommand("hostname")
|
|
|
self.assertTrue(runSetupCommand.endswith(" 8440"))
|
|
@@ -216,7 +216,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_SCP(self, popenMock):
|
|
|
params = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- "1.2.1", "8440")
|
|
|
+ "1.2.1", "8440", "root")
|
|
|
host_log_mock = MagicMock()
|
|
|
log = {'text': ""}
|
|
|
def write_side_effect(text):
|
|
@@ -259,7 +259,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_SSH(self, popenMock):
|
|
|
params = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- "1.2.1", "8440")
|
|
|
+ "1.2.1", "8440", "root")
|
|
|
host_log_mock = MagicMock()
|
|
|
log = {'text': ""}
|
|
|
def write_side_effect(text):
|
|
@@ -315,7 +315,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getOsCheckScript(self):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
ocs = bootstrap_obj.getOsCheckScript()
|
|
|
self.assertEquals(ocs, "scriptDir/os_check_type.py")
|
|
@@ -325,7 +325,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getOsCheckScriptRemoteLocation(self, getRemoteName_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
v = "/tmp/os_check_type1374259902.py"
|
|
|
getRemoteName_mock.return_value = v
|
|
@@ -337,7 +337,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getRepoFile(self, is_suse_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
is_suse_mock.return_value = False
|
|
|
rf = bootstrap_obj.getRepoFile()
|
|
@@ -351,7 +351,7 @@ class TestBootstrap(TestCase):
|
|
|
init_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
expected = 42
|
|
|
init_mock.return_value = None
|
|
@@ -372,7 +372,7 @@ class TestBootstrap(TestCase):
|
|
|
getOsCheckScriptRemoteLocation_mock, getOsCheckScript_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
getOsCheckScript_mock.return_value = "OsCheckScript"
|
|
|
getOsCheckScriptRemoteLocation_mock.return_value = "OsCheckScriptRemoteLocation"
|
|
@@ -392,7 +392,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_getRepoFile(self, hasPassword_mock, getRemoteName_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
# Without password
|
|
|
hasPassword_mock.return_value = False
|
|
@@ -421,7 +421,7 @@ class TestBootstrap(TestCase):
|
|
|
getMoveRepoFileCommand):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
getMoveRepoFileCommand.return_value = "MoveRepoFileCommand"
|
|
|
getRepoDir.return_value = "RepoDir"
|
|
@@ -469,7 +469,7 @@ class TestBootstrap(TestCase):
|
|
|
init_mock, getOsCheckScriptRemoteLocation_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
getOsCheckScriptRemoteLocation_mock.return_value = "OsCheckScriptRemoteLocation"
|
|
|
expected = 42
|
|
@@ -491,7 +491,7 @@ class TestBootstrap(TestCase):
|
|
|
getRunSetupCommand_mock, init_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
getRunSetupCommand_mock.return_value = "RunSetupCommand"
|
|
|
expected = 42
|
|
@@ -511,7 +511,7 @@ class TestBootstrap(TestCase):
|
|
|
hasPassword_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
# With password
|
|
|
hasPassword_mock.return_value = True
|
|
@@ -530,7 +530,7 @@ class TestBootstrap(TestCase):
|
|
|
tmp_dir = tempfile.gettempdir()
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", tmp_dir,
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
done_file = os.path.join(tmp_dir, "hostname.done")
|
|
|
expected = 42
|
|
@@ -547,7 +547,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_checkSudoPackage(self, write_mock, run_mock, init_mock, server_family_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
expected = 42
|
|
|
init_mock.return_value = None
|
|
@@ -565,7 +565,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_checkSudoPackageUbuntu(self, write_mock, run_mock, init_mock, server_family_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "ubuntu12",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
expected = 42
|
|
|
init_mock.return_value = None
|
|
@@ -585,7 +585,7 @@ class TestBootstrap(TestCase):
|
|
|
init_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
expected = 42
|
|
|
getPasswordFile_mock.return_value = "PasswordFile"
|
|
@@ -608,7 +608,7 @@ class TestBootstrap(TestCase):
|
|
|
scp_init_mock, getPasswordFile_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440", password_file="PasswordFile")
|
|
|
+ None, "8440", "root", password_file="PasswordFile")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
getPasswordFile_mock.return_value = "PasswordFile"
|
|
|
# Testing max retcode return
|
|
@@ -641,7 +641,7 @@ class TestBootstrap(TestCase):
|
|
|
run_mock, init_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
expected = 42
|
|
|
getPasswordFile_mock.return_value = "PasswordFile"
|
|
@@ -658,7 +658,7 @@ class TestBootstrap(TestCase):
|
|
|
expected = 43
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
# Normal case
|
|
|
def act_normal_return_int():
|
|
@@ -691,7 +691,7 @@ class TestBootstrap(TestCase):
|
|
|
hasPassword_mock, try_to_execute_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
# Testing workflow without password
|
|
|
bootstrap_obj.copied_password_file = False
|
|
@@ -763,7 +763,7 @@ class TestBootstrap(TestCase):
|
|
|
def test_interruptBootstrap(self, write_mock, createDoneFile_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
bootstrap_obj = Bootstrap("hostname", shared_state)
|
|
|
bootstrap_obj.interruptBootstrap()
|
|
|
self.assertTrue(createDoneFile_mock.called)
|
|
@@ -780,7 +780,7 @@ class TestBootstrap(TestCase):
|
|
|
info_mock, warn_mock, time_mock, sleep_mock):
|
|
|
shared_state = SharedState("root", "sshkey_file", "scriptDir", "bootdir",
|
|
|
"setupAgentFile", "ambariServer", "centos6",
|
|
|
- None, "8440")
|
|
|
+ None, "8440", "root")
|
|
|
n = 180
|
|
|
time = 100500
|
|
|
time_mock.return_value = time
|