def testNewLine(self): testFile = "/tmp/foo.txt" if (os.path.exists(testFile)): os.unlink(testFile) self.assertFalse(os.path.exists(testFile)) cmd = "sleep 1 && echo -e \"foo\\nbar\" > %s" % testFile executor = RemoteShellExecutor("willmore", "localhost", "/home/willmore/.ssh/id_rsa_nopw") executor.run(cmd) #Race condition, but 10 sec should be enough time.sleep(2) self.assertTrue(os.path.exists(testFile)) file = open(testFile, 'r') lines = file.readlines() file.close() self.assertEquals(2, len(lines)) self.assertEquals("foo\n", lines[0]) self.assertEquals("bar\n", lines[1])
def testCanonical(self): testFile = "/tmp/foo.txt" if (os.path.exists(testFile)): os.unlink(testFile) self.assertFalse(os.path.exists(testFile)) cmd = "sleep 1 && echo foo > %s" % testFile executor = RemoteShellExecutor("willmore", "localhost", "/home/willmore/.ssh/id_rsa_nopw") executor.run(cmd) #Race condition, but 10 sec should be enough time.sleep(2) self.assertTrue(os.path.exists(testFile))
# TODO: Keyword will come from user dom = conn.lookupByName("ubuntu10") except: print "No deployment found with that name,creating the one from xml!" dom = libvirt.virConnect.defineXML(conn, domain_xml_file) dom.create() print "going to pinging now..." while ping("192.168.152.2"): print "will sleep now" time.sleep(5) shell_executor = RemoteShellExecutor("q", "192.168.152.2", "/home/sina/.ssh/id_rsa") shell_executor.run("pwd") time.sleep(5) print "Will destroy domain now" dom.destroy() print "Domain destroyed, will sleep for 5 seconds" time.sleep(5) dom.undefine()