def test_push(self): """Push local changes to remote server""" os.mkdir('/tmp/remote_pacha') os.mkdir('/tmp/remote_pacha/hosts/') os.mkdir('/tmp/remote_pacha/hosts/%s' % host.hostname()) mercurial = hg.Hg(port=22, host=host.hostname(), user=self.username, path='/tmp/test_pacha', test=True, conf=self.dict_conf) mercurial.hgrc() mercurial.hg_add() mercurial.commit() mercurial.clone() new_file = open('/tmp/test_pacha/foo', 'w') new_file.write('new line') new_file.close() mercurial.hg_add() mercurial.commit() mercurial.push() hg.update(hosts_path = '/tmp/remote_pacha/hosts') new_line = open('/tmp/remote_pacha/hosts/%s/test_pacha/foo' % host.hostname()) actual = new_line.readlines()[0] expected = 'new line' self.assertEqual(actual, expected)
def test_update(self): """Update a working hg repository""" os.mkdir('/tmp/remote_pacha') os.mkdir('/tmp/remote_pacha/hosts') os.mkdir('/tmp/remote_pacha/hosts/%s' % host.hostname()) mercurial = hg.Hg(port=22, host=host.hostname(), user=self.username, path='/tmp/test_pacha', test=True, conf=self.dict_conf) mercurial.initialize() mercurial.hg_add() mercurial.commit() mercurial.clone() new_line = open('/tmp/test_pacha/foo', 'w') new_line.write('new line') new_line.close() mercurial.hgrc() mercurial.hg_add() mercurial.commit() mercurial.push() hg.update(hosts_path='/tmp/remote_pacha/hosts') self.assertTrue(os.path.isfile('/tmp/remote_pacha/hosts/%s/test_pacha/foo' % host.hostname())) get_line = open('/tmp/remote_pacha/hosts/%s/test_pacha/foo' % host.hostname()) actual = get_line.readlines()[0] expected = 'new line' self.assertEqual(actual, expected)
def retrieve_files(self): """scp all the files we need to /tmp""" os.chdir('/') # avoids being in a dir that will no longer exist if os.path.exists('/tmp/%s' % self.hostname): shutil.move('/tmp/%s' % self.hostname, '/tmp/%s.%s' % (self.hostname, strftime('%H%M%s'))) if not self.directory: rebuild_log.debug("Getting all files (not single dir)") command = "scp -r -P %d %s:%s/%s %s" % (self.port, self.server, self.source, self.hostname, self.destination) rebuild_log.debug(command) else: if self.destination == '/tmp': os.makedirs('/tmp/%s' % (self.hostname)) self.destination = '/tmp/%s/%s' % (self.hostname, self.directory) rebuild_log.debug("Getting a single dir") command = "scp -r -P %d %s:%s/%s/%s %s" % (self.port, self.server, self.source, self.hostname, self.directory, self.destination) rebuild_log.debug(command) call(command, shell=True) # if for some reason the above failed let me know: host_copy = '/tmp/%s' % self.hostname if os.path.isdir(host_copy): # update everything making sure we have the latest rev: try: update(host_copy) except mercurial.error.RepoError: pass # run pre-hooks self.pre_hooks() else: print """ Pacha was not able to retrieve the files from the SSH server provided. Check your configuration file settings and try again.""" sys.exit(1)