Esempio n. 1
0
    def test_normal_flow_update_mode(self):
        utils.init_ignore()

        db = utils.DB(None, [
            utils.Job(tag='test_normal_flow',
                      hosts=[remote_host],
                      using_host=remote_host,
                      remote_path='~/Projects/test-remotedocker/normal-flow',
                      command=['cat', 'supplementary/hello.py'],
                      step=None),
            utils.Job(tag='another_task',
                      hosts=[remote_host],
                      using_host=remote_host,
                      remote_path='~/Projects/test-remotedocker/normal-flow',
                      command=['cat', 'supplementary/hello.py'],
                      step='running')
        ])

        log = run.run(db.jobs[0], db, run.NormalFlow)
        print('run output:', log)
        self.assertEqual(log, 'print(\'hello world!\')')

        _db = utils.DB.load()
        print(_db.dict())
        self.assertDictEqual(_db.latest_job.dict(), db.jobs[0].dict())

        from os import remove
        remove(utils.path_file_ignore())
        remove(utils.path_file_db())
Esempio n. 2
0
    def test_run_with_host(self):
        import arrow
        a = arrow.utcnow()
        d = {
            'latest_host':
            'a',
            'jobs': [{
                'tag': 'test_run_existing',
                'hosts': [remote_host],
                'using_host': remote_host,
                'step': None,
                'docker': 'docker',
                'remote_path': '~/Projects/test-remotedocker/run-with-host',
                'command': ['echo', 'test'],
                'start_time': str(a),
                'container': 'container',
                'oth': dict(a=10),
            }]
        }
        from src import utils
        utils.init_ignore()
        db = utils.DB.parse(d)
        db.save()

        from os.path import join
        file = join(src.utils.path_src(), 'remotedocker.py')
        output = test.utils.run_python(file, 'run', '--tag=test_run_with_host',
                                       '--host={}'.format(remote_host), 'echo',
                                       'test')

        print('run output:', output)

        from os import remove
        remove(utils.path_file_db())
        remove(utils.path_file_ignore())
Esempio n. 3
0
 def test_init_ignore(self):
     from os import remove
     from os.path import exists
     if exists(utils.path_file_ignore()):
         remove(utils.path_file_ignore())
     utils.init_ignore()
     self.assertTrue(exists(utils.path_file_ignore()))
     remove(utils.path_file_ignore())
Esempio n. 4
0
    def test_run(self):
        from src import utils
        utils.init_ignore()

        from os.path import join
        file = join(src.utils.path_src(), 'remotedocker.py')
        output = test.utils.run_python(
            file, 'run', '--tag=test_run', '--host={}'.format(remote_host),
            '--path=~/Projects/test-remotedocker/run-plain', 'echo', 'test')

        print('run output:', output)

        from os import remove
        remove(utils.path_file_db())
        remove(utils.path_file_ignore())
Esempio n. 5
0
    def test_normal_flow_err(self):

        utils.init_ignore()

        db = utils.DB(None, [
            utils.Job(
                tag='test_normal_flow_err',
                hosts=[remote_host],
                using_host=remote_host,
                remote_path='~/Projects/test-remotedocker/normal-flow-err',
                command=['aoeu'],
                step=None)
        ])

        self.assertRaises(utils.errors.WrongExitCode, run.run, db.jobs[0], db,
                          run.NormalFlow)

        _db = utils.DB.load()
        self.assertDictEqual(_db.latest_job.dict(), db.jobs[0].dict())

        from os import remove
        remove(utils.path_file_ignore())
        remove(utils.path_file_db())
Esempio n. 6
0
def main():
    import sys
    from src import utils

    try:
        # init ignore if not exist
        from os.path import exists

        if not exists(utils.path_file_ignore()):
            print('initiating a new .remotedignore, change it to suit your need')
            utils.init_ignore()

        from src.parser import parseargs, Actions
        args = parseargs(sys.argv[1:])

        # register signal
        import signal
        import functools
        signal.signal(signal.SIGINT, functools.partial(act_quit, args=args))

        func_map = {
            Actions.LIST: act_list,
            Actions.RUN: act_run,
            Actions.RESTART: act_restart,
            Actions.STOP: act_stop,
            Actions.REMOVE: act_remove,
            Actions.SSH: act_ssh,
            Actions.SYNC: act_sync,
            Actions.SYNC_UP: act_sync_up,
        }

        # call function
        func_map[args.action](args)
    except utils.errors.RemoteDockerError as e:
        print(e)
        sys.exit(1)
Esempio n. 7
0
    def test_full(self):
        from src import utils
        from os.path import join

        file = join(src.utils.path_src(), 'remotedocker.py')

        utils.init_ignore()
        utils.init_db()
        '''
        Init run
        $ remotedocker run --tag=tag --host=host --path=path echo test
        '''
        print('=====INIT RUN=====')
        test.utils.run_python(file, 'run', '--tag=test_full_first', '--host',
                              remote_host, '--path',
                              '~/Projects/test-remotedocker/full', 'echo',
                              'test')
        '''
        Sync
        '''
        print('=====SYNC DOWN=====')
        test.utils.run_python(file, 'sync')
        '''
        Run again
        $ remotedocker run --tag=tag
        '''
        print('=====RUN AGAIN=====')
        test.utils.run_python(file, 'run', '--tag=test_full_first')
        '''
        Add a host to the same run
        $ remotedocker run --tag=tag --host=newhost
        '''
        print('=====ADD HOST TO THE EXISTING RUN=====')
        db = utils.DB.load()
        db.jobs[0].host = 'somehost'
        db = utils.DB.parse(db.dict())
        db.save()

        db = utils.DB.load()

        print('current host:', db.jobs[0].using_host)

        another_host = remote_host
        test.utils.run_python(file, 'run', '--tag=test_full_first',
                              '--host={}'.format(another_host))
        '''
        Start another run with the same host (latest) (same path)
        $ remotedocker run --tag=newtag echo test2
        '''
        print('=====START ANOTHER RUN WITH THE SAME HOST=====')
        test.utils.run_python(file, 'run', '--tag=test_full_second', 'echo',
                              'test2')
        '''
        Restart the succeeded run
        '''
        print('=====RESTART=====')
        test.utils.run_python(file, 'restart')
        '''
        Stop the succeeded run
        '''
        print('=====STOP THE SUCCEEDED RUN=====')
        self.assertRaises(test.utils.run_python, file, 'stop')
        '''
        Remove the first run
        '''
        print('=====REMOVE THE FIRST RUN=====')
        self.assertRaises(Exception, test.utils.run_python, file, 'rm')
        test.utils.run_python(file, 'rm', 'test_full_first')

        db = utils.DB.load()
        self.assertEqual(len(db.jobs), 1)
        self.assertEqual(db.jobs[0].tag, 'test_full_second')

        from os import remove
        remove(utils.path_file_ignore())
        remove(utils.path_file_db())
Esempio n. 8
0
 def test_rsync_down(self):
     utils.init_ignore()
     rsync.rsync_down(remote_host, '~/Projects/test-remotedocker/rsync')
     from os import remove
     remove(utils.path_file_ignore())