Esempio n. 1
0
    def create_docker_images(self, version):
        ip, user, passwd = DOCKER_MACHINE['ip'], \
                           DOCKER_MACHINE['user'], \
                           DOCKER_MACHINE['passwd']
        print ip, user, passwd
        with create_ssh(ip, user, passwd) as ssh:
            excutor_cmd(ssh, 'mkdir -p {}'.format(DIST_ROOT))
            for project in [
                    'nginx', 'python', 'node', 'dispatcher', 'manager'
            ]:
                if project in ['dispatcher', 'manager']:
                    VERSION[project] = VERSION[project].format(version)
                project_version = VERSION[project]
                project_name = PACKAGE_NAME[project]
                project_name = project_name.format(version=project_version)
                source_path = '{}@{}:{}/{}'.format(
                    SAVE_PACKAGE_MECHINE['user'], SAVE_PACKAGE_MECHINE['ip'],
                    DIST_ROOT, project_name)
                target_path = DIST_ROOT
                excutor_cmd(ssh,
                            'scp {} {}'.format(source_path, target_path),
                            debug=True)

            excutor_cmd(ssh,
                        'cd {} && git pull origin master'.format(ANT_BUILD))
            excutor_cmd(ssh,
                        'cd {} && sh {} {}'.format(ANT_BUILD,
                                                   'docker_build.sh', version),
                        debug=True)
Esempio n. 2
0
 def agent_install_directory_should_be_exists(self, ips, user, passwd,
                                              install_dir):
     for ip in json.loads(ips):
         with create_ssh(ip, user, passwd) as ssh:
             out, err = excutor_cmd(ssh, 'ls {}'.format(install_dir))
             if not out:
                 raise Exception('{} not exists on {}'.format(
                     install_dir, ip))
Esempio n. 3
0
 def agent_process_shuold_not_be_exists_on(self, ips, user, passwd):
     check_cmd = 'ps -ef|grep "agent/embedded/bin/python"|grep -v grep|wc -l'
     for ip in json.loads(ips):
         with create_ssh(ip, user, passwd) as ssh:
             out, err = excutor_cmd(ssh, check_cmd)
             if int(out) != 0:
                 raise Exception(
                     'Install faild,Only {} process on {}'.format(
                         int(out), ip))
Esempio n. 4
0
 def check_if_exists_dependecies(self, dependencies):
     ip, user, passwd = DEPLOY_MECHINE['ip'], \
                        DEPLOY_MECHINE['user'], \
                        DEPLOY_MECHINE['passwd']
     with create_ssh(ip, user, passwd) as ssh:
         for item in dependencies.split(','):
             out, err = excutor_cmd(ssh, 'ls {}'.format(INSTALL_DIR[item]))
             if not out:
                 self.install_omp_package(item)
Esempio n. 5
0
 def stop_omp_package(self, project_name):
     ip, user, passwd = DEPLOY_MECHINE['ip'], \
                        DEPLOY_MECHINE['user'], \
                        DEPLOY_MECHINE['passwd']
     yaml_file = "{}/{}".format(BASE_DIR, 'project_command.yaml')
     stop_cmd = parase_yaml_file(yaml_file)[project_name]['exec_stop']
     print stop_cmd
     with create_ssh(ip, user, passwd) as ssh:
         excutor_cmd(ssh, stop_cmd, debug=True)
Esempio n. 6
0
 def check_if_exist_process(self, project_name):
     ip, user, passwd = DEPLOY_MECHINE['ip'], \
                        DEPLOY_MECHINE['user'], \
                        DEPLOY_MECHINE['passwd']
     yaml_file = "{}/{}".format(BASE_DIR, 'project_command.yaml')
     check_cmd = parase_yaml_file(yaml_file)[project_name]['exec_status']
     with create_ssh(ip, user, passwd) as ssh:
         out, err = excutor_cmd(ssh, check_cmd)
         if int(out) != 0:
             raise Exception("{} check faild".format(check_cmd))
Esempio n. 7
0
 def uninstall_omp_package(self, project_name):
     ip, user, passwd = DEPLOY_MECHINE['ip'], \
                        DEPLOY_MECHINE['user'], \
                        DEPLOY_MECHINE['passwd']
     yaml_file = "{}/{}".format(BASE_DIR, 'project_command.yaml')
     uninstall_cmd = parase_yaml_file(
         yaml_file)[project_name]['exec_uninstall']
     with create_ssh(ip, user, passwd) as ssh:
         excutor_cmd(ssh, uninstall_cmd)
     return (ip, user, passwd, INSTALL_DIR[project_name])
Esempio n. 8
0
    def upload_omp_package(self, project_name, version):
        ip, user, passwd = DEPLOY_MECHINE['ip'], \
                           DEPLOY_MECHINE['user'], \
                           DEPLOY_MECHINE['passwd']
        with create_ssh(ip, user, passwd) as ssh:
            excutor_cmd(ssh, 'mkdir -p {}'.format(TEMP_INSTALL_PATH))

        file_name = PACKAGE_NAME[project_name].format(version=version)
        ip, user, passwd = SAVE_PACKAGE_MECHINE['ip'], \
                           SAVE_PACKAGE_MECHINE['user'], \
                           SAVE_PACKAGE_MECHINE['passwd']
        with create_ssh(ip, user, passwd) as ssh:
            source_path = '{}/{}'.format(DIST_ROOT, file_name)
            target_path = 'root@{}:{}'.format(DEPLOY_MECHINE['ip'],
                                              TEMP_INSTALL_PATH)
            print 'scp {} {}'.format(source_path, target_path)
            excutor_cmd(ssh,
                        'scp {} {}'.format(source_path, target_path),
                        debug=True)
Esempio n. 9
0
 def check_if_docker_images_create_sucess(self, images_name):
     ip, user, passwd = DOCKER_MACHINE['ip'], \
                        DOCKER_MACHINE['user'], \
                        DOCKER_MACHINE['passwd']
     with create_ssh(ip, user, passwd) as ssh:
         out, err = excutor_cmd(
             ssh, 'docker images|grep {} |grep -v grep |wc -l'.format(
                 images_name))
         if not out:
             raise Exception('Images create faild')
Esempio n. 10
0
 def agent_install_directory_should_be_delete(self, ips, user, passwd,
                                              install_dir):
     for ip in json.loads(ips):
         with create_ssh(ip, user, passwd) as ssh:
             out, err = excutor_cmd(
                 ssh,
                 'python -c "import os; exit(int(os.path.exists(\'{}\')))" '
                 .format(install_dir))
             if out:
                 raise Exception('{} not exists on {}'.format(
                     install_dir, ip))
Esempio n. 11
0
    def build_package(self, project_name, branch):
        yaml_file = join(BASE_DIR,'build_machine.yaml')
        info = parase_yaml_file(yaml_file)[project_name]
        project_name = project_name.split('-')[0]
        if project_name == 'dispatcher':
            with_module = WITH_MODULE
        else:
            with_module = ''
        
        ip = info['ip']
        user = info['user']
        passwd = info['passwd']
        system_platform = info['platform']
        system_bit = info['system_bit']
        build_system = info['build_system']
        python_exe = info['python_exe']
        postfix = info['postfix']

        build_cmd = BUILD_CMD.format(
            python_exe,
            project_name,
            branch,
            build_system,
            with_module
        )

        build_cmd = ('cd {} && {}').format(ANT_BUILD, build_cmd)
        print build_cmd
        with create_ssh(ip, user, passwd) as ssh:
            excutor_cmd(ssh, build_cmd, debug=True)
            manifest_path = '{}/{}/{}'.format(PROJECT_ROOT, project_name, 'manifest.yaml')
            module_path = '{}/{}/{}'.format(PROJECT_ROOT, project_name, 'module.yaml')
  
            out, err = excutor_cmd(ssh, 'cat {}'.format(manifest_path), debug=True)
            if not out:
                out, err = excutor_cmd(ssh, 'cat {}'.format(module_path), debug=True)
            project_version = yaml.load(out)['version']
            package_name = PACKAGE_NAME[project_name]
            file_name = package_name.format(
                system_platform=system_platform,
                system_bit=system_bit,
                version=project_version,
                postfix=postfix
            )
            source_path = '{}/{}'.format(DIST_ROOT, file_name)
            target_path = 'root@{}:{}'.format(SAVE_PACKAGE_MECHINE['ip'], DIST_ROOT)
            scp_cmd = 'scp {} {}'.format(source_path, target_path)

            if ip != SAVE_PACKAGE_MECHINE['ip']:
                excutor_cmd(ssh, scp_cmd,debug=True)
        return (ip, user, passwd, source_path)
Esempio n. 12
0
    def upload_assign_version_agent(self, version, system):
        if 'win' in system:
            postfix = 'zip'
        else:
            postfix = 'tar.gz'
        version = '2.0.{}'.format(version.lstrip('R'))
        agent_name = 'agent-{}-{}.{}'.format(system, version, postfix)
        agent_latest = 'agent-{}-{}.{}'.format(system, version, postfix)
        agent_path = '{}/{}'.format(DIST_ROOT, agent_name)

        ip, user, passwd = SAVE_PACKAGE_MECHINE['ip'], \
                           SAVE_PACKAGE_MECHINE['user'], \
                           SAVE_PACKAGE_MECHINE['passwd']
        target_path = '{}@{}:{}/repo'.format(DEPLOY_MECHINE['user'],
                                             DEPLOY_MECHINE['ip'],
                                             INSTALL_DIR['dispatcher'])
        with create_ssh(ip, user, passwd) as ssh:
            out, err = excutor_cmd(ssh, 'ls {}'.format(agent_path))
            if not out:
                raise Exception(
                    'agent-{} do not exists,need build agent package'.format(
                        version))
            excutor_cmd(ssh, 'scp {} {}'.format(agent_path, target_path))

        ip, user, passwd = DEPLOY_MECHINE['ip'], \
                           DEPLOY_MECHINE['user'], \
                           DEPLOY_MECHINE['passwd']

        with create_ssh(ip, user, passwd) as ssh:
            agent_path = '{}/repo/{}'.format(INSTALL_DIR['dispatcher'],
                                             agent_name)
            out, err = excutor_cmd(ssh, 'ls {}'.format(agent_path))
            if not out:
                raise Exception("agent package upload faild")
            excutor_cmd(
                ssh, 'cd {}/repo && rm -rf {} && ln -s {} {}'.format(
                    INSTALL_DIR['dispatcher'], agent_latest, agent_name,
                    agent_latest))
Esempio n. 13
0
 def install_omp_package(self, project_name, version):
     ip, user, passwd = DEPLOY_MECHINE['ip'], \
                        DEPLOY_MECHINE['user'], \
                        DEPLOY_MECHINE['passwd']
     file_name = PACKAGE_NAME[project_name].format(version=version)
     file_name = '{}/{}'.format(TEMP_INSTALL_PATH, file_name)
     file_path = 'platform-ant-{}'.format(project_name)
     install_script = '{}/{}/{}'.format(TEMP_INSTALL_PATH, file_path,
                                        'install.sh')
     install_command = INSTALL_CMD.format(install_script)
     print install_command
     with create_ssh(ip, user, passwd) as ssh:
         excutor_cmd(ssh,
                     'tar zxf {} -C {}'.format(file_name,
                                               TEMP_INSTALL_PATH),
                     debug=True)
         excutor_cmd(ssh, install_command, debug=True)
     return (ip, user, passwd, INSTALL_DIR[project_name])
Esempio n. 14
0
 def check_if_not_exist_file(self, filepath):
     ip, user, passwd, file_path = filepath
     with create_ssh(ip, user, passwd) as ssh:
         stdout, stderr = excutor_cmd(ssh, 'ls {}'.format(file_path))
         if stdout:
             raise Exception('{} not found in {}'.format(file_path, ip))
Esempio n. 15
0
 def demo(self, host, username, password):
     with create_ssh(host, username, password) as ssh:
         excutor_cmd(ssh, 'ls -l /tmp')