Exemplo n.º 1
0
 def _make_test_repo(clazz):
     repo = git_temp_repo(debug=clazz.DEBUG)
     src_dir = path.normpath(
         path.join(path.dirname(__file__), '../../../../bes_bash'))
     dst_dir = path.join(repo.root, 'bash/bes_bash_one_file')
     tar_util.copy_tree(src_dir, dst_dir)
     repo.add(['bash'])
     repo.commit('add', ['bash'])
     repo.push('-u', 'origin', 'master')
     return repo
Exemplo n.º 2
0
 def test_copy_tree_and_excludes(self):
   self.maxDiff = None
   src_tmp_dir = self.make_temp_dir(suffix = '.src_dir')
   dst_tmp_dir = self.make_temp_dir(suffix = '.dst_dir')
   with tarfile.open(self.data_path('test.tar'), mode = 'r') as f:
     f.extractall(path = src_tmp_dir)
   tar_util.copy_tree(src_tmp_dir, dst_tmp_dir, excludes = [ 'bar.txt', 'foo.txt' ])
   
   expected_files = [
     self.native_filename('1'),
     self.native_filename('1/2'),
     self.native_filename('1/2/3'),
     self.native_filename('1/2/3/4'),
     self.native_filename('1/2/3/4/5'),
     self.native_filename('1/2/3/4/5/apple.txt'),
     self.native_filename('1/2/3/4/5/kiwi.txt'),
     self.native_filename('empty'),
     self.native_filename('kiwi_link.txt'),
   ]
   actual_files = file_find.find(dst_tmp_dir, file_type = file_find.ANY)
   self.assertEqual( expected_files, actual_files )
Exemplo n.º 3
0
  def main(self):
    p = argparse.ArgumentParser()
    vmware_options_cli_args.add_arguments(p)
    p.add_argument('--tail-log', action = 'store_true', default = False,
                   help = 'Tail the log [ False ]')
    p.add_argument('--dir', action = 'store', default = os.getcwd(),
                   dest = 'source_dir',
                   help = 'Directory to use for the package [ False ]')
    p.add_argument('-o', '--output', action = 'store', default = None,
                   dest = 'output_filename',
                   help = 'Output the log to filename instead of stdout [ False ]')
    p.add_argument('--clone-vm', action = 'store_true', default = False,
                   help = 'Run programs in a clone of the vm [ False ]')
    p.add_argument('vm_id', action = 'store', default = None,
                   help = 'The vmware vmx filename for the vm to test [ None ]')
    p.add_argument('entry_command_args', action = 'store', default = [], nargs = '*',
                   help = 'Optional entry command args [ ]')
    args = p.parse_args()

    self._debug = args.debug
    self._name = path.basename(sys.argv[0])
    tmp_dir = tempfile.mkdtemp()

    tar_util.copy_tree(args.source_dir,
                       tmp_dir,
                       excludes = self._PACKAGE_EXCLUDES)
    entry_command_path = path.join(tmp_dir, self._ENTRY_COMMAND_FILENAME)
    file_util.save(entry_command_path, content = self._ENTRY_COMMAND_CONTENT)

    env = os_env.clone_current_env(d = {
      'xBES_LOG': 'vmware=debug',
    })

    extra_args = []
    if args.debug:
      extra_args.append('--debug')
    if args.tty:
      extra_args.extend([ '--tty', tty ])
    if args.tail_log:
      extra_args.append('--tail-log')
    if args.clone_vm:
      extra_args.append('--clone-vm')
    if args.output_filename:
      extra_args.extend([ '--output', args.output_filename ])
    if args.config_filename:
      print(config_filename)
      extra_args.extend([ '--config', args.config_filename ])
    if args.vmrest_username:
      extra_args.extend([ '--vmrest-username', args.vmrest_username ])
    if args.vmrest_password:
      extra_args.extend([ '--vmrest-password', args.vmrest_password ])
    if args.vmrest_port:
      extra_args.extend([ '--vmrest-port', str(args.vmrest_port) ])
    if args.login_username:
      extra_args.extend([ '--login-username', args.login_username ])
    if args.login_password:
      extra_args.extend([ '--login-password', args.login_password ])
    cmd = [
      'bin/best.py',
      'vmware', 'vm_run_package',
    ] + extra_args + [
      args.vm_id,
      tmp_dir,
      self._ENTRY_COMMAND_FILENAME,
    ] + args.entry_command_args
    self._log.log_d('cmd={}'.format(' '.join([ str(x) for x in cmd ])))
    rv = execute.execute(cmd,
                         env = env,
                         raise_error = False,
                         shell = False,
                         non_blocking = True,
                         stderr_to_stdout = True)
    if rv.exit_code != 0:
      print(rv.stdout)
    return rv.exit_code