Ejemplo n.º 1
0
    def init_database(self, database):
        with tempfile.NamedTemporaryFile(mode='w') as f:
            f.write(
                "CREATE DATABASE IF NOT EXISTS {0};".format(
                    database.get('dbname')), )
            f.flush()
            status, stdout = utils.run_cmd(['mysql', '-uroot', '<', f.name])
            if status != 0:
                raise Exception('create database failed')

        file_context = [
            "GRANT ALL ON {0}.* TO '{1}'@'%' identified by "
            "'{2}';\n".format(database.get('dbname'), database.get('username'),
                              database.get('password')),
            "GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'localhost' "
            "IDENTIFIED BY '{2}';\n".format(database.get('dbname'),
                                            database.get('username'),
                                            database.get('password')),
            "GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'%' IDENTIFIED BY "
            "'{2}';\n".format(database.get('dbname'), database.get('username'),
                              database.get('password')),
            "GRANT ALL PRIVILEGES ON {0}.* TO '{1}'@'{3}' IDENTIFIED BY "
            "'{2}';\n".format(database.get('dbname'), database.get('username'),
                              database.get('password'), socket.gethostname()),
        ]
        LOG.debug('db file:\n %s', ''.join(file_context))
        with tempfile.NamedTemporaryFile(mode='w') as f:
            f.writelines(file_context)
            f.flush()
            status, stdout = utils.run_cmd(['mysql', '-uroot', '<', f.name])
            if status != 0:
                raise Exception('set privileges failed ')
Ejemplo n.º 2
0
 def __cmake(self):
     if os.path.exists(self.build_dir):
         shutil.rmtree(self.build_dir)
     os.mkdir(self.build_dir)
     os.chdir(self.build_dir)
     # print("\n\033[1;45;32m Cmake ... \033[0m\n")
     run_cmd("cmake ..")
Ejemplo n.º 3
0
    def test_create_project_user_role(self):
        status, stdout = self.create_project()
        self.assertEqual(status, 0, 'create project failed')
        status, stdout = self.create_user()
        self.assertEqual(status, 0, 'create user failed')

        status, _ = utils.run_cmd([
            'source',
            self.admin_openrc,
            '&&',
            'openstack',
            'role',
            'create',
            self.test_user_role,
        ])
        self.assertEqual(status, 0, 'create role failed')
        self.addCleanup(utils.run_openstack_cmd, self.admin_openrc,
                        ['role', 'delete', self.test_user_role])
        status, _ = utils.run_cmd([
            'source',
            self.admin_openrc,
            '&&',
            'openstack',
            'role',
            'add',
            '--project',
            self.test_user_project,
            '--user',
            self.test_user_name,
            self.test_user_role,
        ])
        self.assertEqual(status, 0, 'add role failed')
Ejemplo n.º 4
0
 def grade_A2(self):
     """A2: git commits"""
     cmd = (
         "git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%C"
         "reset %s %Cgreen(%cD) %C(bold blue)<%an>%Creset' "
         "--abbrev-commit")
     u.run_cmd(cmd)
Ejemplo n.º 5
0
 def test_OS004(self):
     """Check the VSC/ION driver"""
     out = run_cmd("lsmod | grep myd_vsc")
     self.assertNotEqual(out,
                         "",
                         msg="\033[31m not found myd_vsc driver\033[0m")
     out = run_cmd("lsmod | grep myd_ion")
     self.assertNotEqual(out,
                         "",
                         msg="\033[31m not found myd_ion driver\033[0m")
Ejemplo n.º 6
0
 def load_ssh(self):
     cmd = "./modules/sh/ssh_load.sh"
     ret = utils.run_cmd(cmd, True)
     if ret[0] == 1:
         return True
     elif ret[0] == 0:
         return False
Ejemplo n.º 7
0
 def clean_up(self):
     """Clean Up Resources
     """
     if self.conf.get('clean_up_dir'):
         utils.rm_path(self.conf.get('clean_up_dir'))
     database = self.conf.get('database')
     if database:
         if isinstance(database, collections.Sequence):
             database_list = [db['dbname'] for db in database]
         else:
             database_list = [database['dbname']]
         for db in database_list:
             LOG.debug('drop database %s', db)
             utils.run_cmd([
                 'mysql', '-uroot', '-e',
                 '"DROP DATABASE IF EXISTS {0}"'.format(db)
             ])
Ejemplo n.º 8
0
 def create_project(self):
     status, stdout = utils.run_cmd([
         'source', self.admin_openrc, '&&', 'openstack', 'project',
         'create', self.test_user_project, '--domain', 'default',
         '--description', '"Test Project"'
     ])
     self.addCleanup(utils.run_openstack_cmd, self.admin_openrc,
                     ['project', 'delete', self.test_user_project])
     return status, stdout
Ejemplo n.º 9
0
    def login_password(self, passwd):
        cmd = "su %s"%self.user
        ret = utils.run_cmd(cmd, False, passwd)
        self.parent.footer.original_widget.set_text(str(ret))
        if ret[0] != 0:
            self.parent.is_login = False

            return False
        else:
            return True
Ejemplo n.º 10
0
    def after_start(self):
        """After Start Services
        """
        if self.conf.get('enable_management'):
            LOG.debug('enable rabbitmq management')
            status, stdout = utils.run_cmd(
                ['rabbitmq-plugins', 'enable', 'rabbitmq_management']
            )
            if status != 0:
                LOG.error('enable rabbitmq management failed')

        init_user = self.conf.get('init_user')
        if init_user:
            utils.run_cmd([
                'rabbitmqctl', 'add_user',
                init_user.get('name'), init_user.get('password')
            ])
            utils.run_cmd([
                'rabbitmqctl', 'set_permissions', '-p', '/',
                init_user.get('name'), '".*" ".*" ".*"'
            ])
Ejemplo n.º 11
0
    def apply(self, button):
        new_password = self.edits[0].original_widget.get_edit_text()
        confirm_password = self.edits[1].original_widget.get_edit_text()

        if new_password != confirm_password:
            self.parent.footer.original_widget.set_text("Password is not matched!")
            return False

        if new_password == "" and confirm_password == "":
            new_password = "******"

        pass_prama = "-o" if self.ssh_login is True else "-c"
        msg = "open" if self.ssh_login else "close"

        cmd_password = "******"%new_password
        ret_password = utils.run_cmd(cmd_password, True)
        cmd_ssh = "./modules/sh/ssh_login.sh %s"%pass_prama
        ret_ssh = utils.run_cmd(cmd_ssh, True)

        if ret_password[0] == 0:
            if ret_ssh[0] == 0:
                self.parent.footer.original_widget.set_text("Update password success,"
                                                            " ssh login is %s now"%msg)
            else:
                self.parent.footer.original_widget.set_text("Update password success, %s ssh login fail"%msg)


        elif ret_password[0] == 222:
            # change ssh status but not modify password
            if ret_ssh[0] == 0:
                self.parent.footer.original_widget.set_text("ssh login is %s now"%msg)
            else:
                self.parent.footer.original_widget.set_text("%s ssh login fail"%str(ret_ssh))


        else:
            self.parent.footer.original_widget.set_text("Update password error: %s"%str(ret_password))

        self.edits[0].original_widget.set_edit_text("")
        self.edits[1].original_widget.set_edit_text("")
Ejemplo n.º 12
0
    def test_SC005(self):
        """Soft reset each MYDX"""
        RUN_TIMES = 30
        case_id = get_current_func_name()[5:]
        rv = None
        for i in range(RUN_TIMES):
            self._run_server('{}_{}'.format(case_id, i))
            with open(self.server.get_log()) as f:
                for line in f:
                    if 'SERVICE IS READY' in line:
                        rv = True
                        break
                    elif 'ERROR' in line:
                        rv = False
            # can normally start hddldamon
            boot_device_count = int(run_cmd('lsusb| grep "f63b"|wc -l'))
            LOGGER.info('Ran {} times.'.format(i))
            self.assertEqual(self.device_count, boot_device_count)
            self.assertTrue(rv)


# class SampleTest(unittest.TestCase):
#
#         base_dir = os.path.join(HDDL_SOURCE_DIR, 'hddl-samples')
#
#     def setUpClass(cls):
#         if not os.path.exists(cls.base_dir):
#             raise ValueError('HDDL Sample source Dir not exists')
#         current_pwd = os.getcwd()
#         os.chdir(os.path.join(cls.base_dir,))
#         _root_no_password('')
#
#     def test_barrier(self):
#         pass
#
#     def test_cross_road(self):
#         pass
#
#     def test_indoor(self):
#         pass
Ejemplo n.º 13
0
def create_l3a_composite(
    synthdate, synth_halflength, tile, imagery_date_list, window_size
):
    """
        Major steps:

        2. Construct command including imagery
        3. Upload result to S3
    """
    logging.info("run composite command here\n\n\n\n\n")
    logging.info("----------------------------------------")

    path_list = find_l2a_xml_paths_in_working_folder(imagery_date_list, tile)

    logging.info(path_list)

    composite_command = f'/usr/bin/composite_processing.py --tileid {tile} --syntdate {synthdate} --synthalf {synth_halflength} --input {" ".join([str(p) for p in path_list])} --res 10 --outdir {OUTPUT_FOLDER_PATH} --bandsmap /usr/share/sen2agri/bands_mapping_s2_L8.txt --scatteringcoef /usr/share/sen2agri/scattering_coeffs_10m.txt'

    logging.info(composite_command)

    result = run_cmd(composite_command)

    return result
Ejemplo n.º 14
0
def create_l3b_monodate_single_date(imagery_date, tile, working_folder):
    """
        Major steps:

        2. Construct command including imagery
        3. Upload result to S3
    """
    logging.info("run lai command here\n\n\n\n\n")
    logging.info("----------------------------------------")

    path_list = find_l2a_xml_paths_in_folder([imagery_date], tile,
                                             working_folder)

    output_folder = Path(working_folder, "output")

    logging.info(path_list)

    lai_command = f'/usr/bin/lai_retrieve_processing.py --tileid {tile} --input {" ".join([str(p) for p in path_list])} --res 10 --outdir {output_folder} --rsrcfg /usr/share/sen2agri/rsr_cfg.txt --modelsfolder {working_folder} --generatemodel YES --generatemonodate YES --genreprocessedlai NO --genfittedlai NO'

    logging.info(lai_command)

    result = run_cmd(lai_command)

    return result
Ejemplo n.º 15
0
 def test_OS005(self):
     """Check the ION device"""
     out = run_cmd("ls /dev/ion")
     self.assertNotEqual(out,
                         "",
                         msg="\033[31m not found myd_vsc device\033[0m")
Ejemplo n.º 16
0
 def db_sync(self):
     """Update Database"""
     status, stdout = utils.run_cmd(self.conf.get('db_sync_cmd'))
     if status != 0:
         raise Exception('db sync failed, {0}'.format(stdout))
Ejemplo n.º 17
0
def openssl_rand_hex10(loader, node):
    _, stdout = utils.run_cmd(['openssl', 'rand', '-hex', '10'])
    return stdout
Ejemplo n.º 18
0
 def _get_device_count(cls):
     return int(run_cmd('lsusb | grep "03e7" | wc -l'))
Ejemplo n.º 19
0
 def test_show_admin(self):
     status, _ = utils.run_cmd([
         'source', self.admin_openrc, '&&', 'openstack', 'user', 'show',
         'admin'
     ])
     self.assertEqual(status, 0, 'show admin failed')
Ejemplo n.º 20
0
 def test_token_issue(self):
     status, _ = utils.run_cmd(
         ['source', self.admin_openrc, '&&', 'openstack', 'token', 'issue'])
     self.assertEqual(status, 0, 'token issue failed')
Ejemplo n.º 21
0
 def __make(self):
     os.chdir(self.build_dir)
     # print("\n\033[1;45;32m Make ... \033[0m\n")
     run_cmd("make clean")
     run_cmd("make -j8")
Ejemplo n.º 22
0
 def __memory_info():
     output = run_cmd("free")
     mem_log = re.sub(' +', ' ', output.strip())
     mem_str = mem_log.split(" ")[7]
     mem = int(int(mem_str) / 1024)
     return mem
Ejemplo n.º 23
0
 def grade_A1(self):
     """A1: check for compilation artifacts"""
     # -a for all files
     # -C for colorized output
     # -I to ignore the .git dir
     u.run_cmd("tree -a -C -I '.git'")