Пример #1
0
 def test__build_deploy_virtualenv__package_tools__up_to_date(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     venv_bin_dir = os.path.join(venv_path, 'bin')
     venv_pip = os.path.join(venv_bin_dir, 'pip')
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     major_versions = {
         'pip': 9,
         'setuptools': 36
     }
     with open(config_file, 'w') as config_handle:
         config_handle.write(
             "[global]\nname=%s\nvirtualenv_dir=%s\n"
             "[pip]\ndeps=serviceping<18.0.0\n" % (
                 venv_name,
                 self.venv_dir
             )
         )
     deploy.build_deploy_virtualenv(configuration=[config_file], verbose=False)
     output = subprocess.check_output([venv_pip, 'list', '--format=columns'])
     for line in output.decode().split(os.linesep):
         try:
             package, version = line.split()
         except ValueError:
             continue
         package = package.strip()
         if package in major_versions.keys():
             version = version.strip('(').strip(')')
             major = int(version.split('.')[0])
             self.assertGreaterEqual(major, major_versions[package])
Пример #2
0
 def test__build_deploy_virtualenv__pips(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write(
             "[global]\nname=%s\nvirtualenv_dir=%s\n"
             "[pip]\ndeps=serviceping<18.0.0\n" % (
                 venv_name,
                 self.venv_dir
             )
         )
     deploy.build_deploy_virtualenv(configuration=[config_file], verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
     confdir = os.path.join(venv_path, 'conf')
     predeploy_file = os.path.join(confdir, 'binfiles_predeploy.json')
     postdeploy_file = os.path.join(confdir, 'binfiles_postdeploy.json')
     self.assertTrue(os.path.isdir(confdir))
     print(os.listdir(confdir))
     self.assertTrue(os.path.exists(predeploy_file))
     self.assertTrue(os.path.exists(postdeploy_file))
     with open(predeploy_file, 'r') as predeploy_handle:
         predeploy = json.load(predeploy_handle)
         print('predeploy', predeploy)
         self.assertIsInstance(predeploy, dict)
     with open(postdeploy_file, 'r') as postdeploy_handle:
         postdeploy = json.load(postdeploy_handle)
         print('postdeploy', postdeploy)
         self.assertIsInstance(postdeploy, dict)
     self.assertEqual(list(deploy.deployed_bin_files(venv_path).keys()), ['serviceping'])
Пример #3
0
 def test__build_deploy_virtualenv__pips(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write("[global]\nname=%s\nvirtualenv_dir=%s\n"
                             "[pip]\ndeps=serviceping<18.0.0\n" %
                             (venv_name, self.venv_dir))
     deploy.build_deploy_virtualenv(configuration=[config_file],
                                    verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
     confdir = os.path.join(venv_path, 'conf')
     predeploy_file = os.path.join(confdir, 'binfiles_predeploy.json')
     postdeploy_file = os.path.join(confdir, 'binfiles_postdeploy.json')
     self.assertTrue(os.path.isdir(confdir))
     print(os.listdir(confdir))
     self.assertTrue(os.path.exists(predeploy_file))
     self.assertTrue(os.path.exists(postdeploy_file))
     with open(predeploy_file, 'r') as predeploy_handle:
         predeploy = json.load(predeploy_handle)
         print('predeploy', predeploy)
         self.assertIsInstance(predeploy, dict)
     with open(postdeploy_file, 'r') as postdeploy_handle:
         postdeploy = json.load(postdeploy_handle)
         print('postdeploy', postdeploy)
         self.assertIsInstance(postdeploy, dict)
     self.assertEqual(list(deploy.deployed_bin_files(venv_path).keys()),
                      ['serviceping'])
Пример #4
0
 def test__build_deploy_virtualenv__package_tools__up_to_date(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     venv_bin_dir = os.path.join(venv_path, 'bin')
     venv_pip = os.path.join(venv_bin_dir, 'pip')
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     major_versions = {'pip': 9, 'setuptools': 36}
     with open(config_file, 'w') as config_handle:
         config_handle.write("[global]\nname=%s\nvirtualenv_dir=%s\n"
                             "[pip]\ndeps=serviceping<18.0.0\n" %
                             (venv_name, self.venv_dir))
     deploy.build_deploy_virtualenv(configuration=[config_file],
                                    verbose=False)
     output = subprocess.check_output(
         [venv_pip, 'list', '--format=columns'])
     for line in output.decode().split(os.linesep):
         try:
             package, version = line.split()
         except ValueError:
             continue
         package = package.strip()
         if package in major_versions.keys():
             version = version.strip('(').strip(')')
             major = int(version.split('.')[0])
             self.assertGreaterEqual(major, major_versions[package])
Пример #5
0
 def test__build_deploy_virtualenv(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write("[global]\nname=%s\nvirtualenv_dir=%s\n"
                             "[pip]\ndeps:\n    pip\n" %
                             (venv_name, self.venv_dir))
     deploy.build_deploy_virtualenv(configuration=[config_file],
                                    verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
Пример #6
0
 def test__build_deploy_virtualenv__no_pips(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write("[global]\nname=%s\nvirtualenv_dir=%s\n" %
                             (venv_name, self.venv_dir))
     deploy.build_deploy_virtualenv(configuration=[config_file],
                                    verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
     confdir = os.path.join(venv_path, 'conf')
     self.assertTrue(os.path.isdir(confdir))
     self.assertTrue(
         os.path.exists(os.path.join(confdir, 'binfiles_predeploy.json')))
Пример #7
0
 def test__build_deploy_virtualenv__pips__linkbins(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write("[global]\nname=%s\nvirtualenv_dir=%s\n"
                             "[pip]\ndeps=serviceping<18.0.0\n" %
                             (venv_name, self.venv_dir))
     deploy.build_deploy_virtualenv(configuration=[config_file],
                                    verbose=False)
     with TemporaryDirectory() as bindir:
         deploy.link_deployed_bin_files(venv_path, bindir)
         self.assertIn('serviceping', os.listdir(bindir))
         deploy.unlink_deployed_bin_files(venv_path)
         self.assertEqual([], os.listdir(bindir))
Пример #8
0
 def test__build_deploy_virtualenv(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write(
             "[global]\nname=%s\nvirtualenv_dir=%s\n"
             "[pip]\ndeps:\n    pip\n" % (
                 venv_name,
                 self.venv_dir
             )
         )
     deploy.build_deploy_virtualenv(
         configuration=[config_file],
         verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
Пример #9
0
 def test__build_deploy_virtualenv__pips__linkbins(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write(
             "[global]\nname=%s\nvirtualenv_dir=%s\n"
             "[pip]\ndeps=serviceping<18.0.0\n" % (
                 venv_name,
                 self.venv_dir
             )
         )
     deploy.build_deploy_virtualenv(
         configuration=[config_file],
         verbose=False)
     with TemporaryDirectory() as bindir:
         deploy.link_deployed_bin_files(venv_path, bindir)
         self.assertIn('serviceping', os.listdir(bindir))
         deploy.unlink_deployed_bin_files(venv_path)
         self.assertEqual([], os.listdir(bindir))
Пример #10
0
 def test__build_deploy_virtualenv__no_pips(self):
     sys.argv = ['foo']
     venv_name = 'deploy_default'
     venv_path = os.path.join(self.venv_dir, venv_name)
     config_file = os.path.join(self.venv_dir, 'deploy_default.conf')
     with open(config_file, 'w') as config_handle:
         config_handle.write(
             "[global]\nname=%s\nvirtualenv_dir=%s\n" % (
                 venv_name,
                 self.venv_dir
             )
         )
     deploy.build_deploy_virtualenv(
         configuration=[config_file],
         verbose=False)
     self.assertTrue(os.path.isdir(venv_path))
     confdir = os.path.join(venv_path, 'conf')
     self.assertTrue(os.path.isdir(confdir))
     self.assertTrue(
         os.path.exists(
             os.path.join(confdir, 'binfiles_predeploy.json')
         )
     )
Пример #11
0
if __name__ == "__main__":
    # logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(sys.argv[0])

    logger.debug('Running post install steps, from directory %r' % os.getcwd())

    if not os.path.exists('deploy.conf'):
        print("No 'deploy.conf' found.  Doing nothing", file=sys.stderr)
        sys.exit(1)

    logger.debug('Using the following deploy.conf: %s' %
                 open('deploy.conf').read())

    venv_directory = None
    try:
        venv_directory = build_deploy_virtualenv(update_existing=True)
        update_config(venv_directory)
    except:
        print('Unable to create the python virtualenv', file=sys.stderr)
        logger.exception(
            'The virtualenv create failed, removing venv_directory')
        if venv_directory and os.path.exists(venv_directory):
            print('Removing the %r virtualenv directory' % venv_directory)
            shutil.rmtree(venv_directory)
        sys.exit(1)

    try:
        if get_config_flag('global', 'link_bin_files'):
            logger.debug('Linking files in the virtualenv bin directory to %r',
                         os.path.dirname(sys.executable))
            try:
Пример #12
0
if __name__ == "__main__":
    # logging.basicConfig(level=logging.DEBUG)
    logger = logging.getLogger(sys.argv[0])

    logger.debug('Running post install steps, from directory %r' % os.getcwd())

    if not os.path.exists('deploy.conf'):
        print("No 'deploy.conf' found.  Doing nothing", file=sys.stderr)
        sys.exit(1)

    logger.debug('Using the following deploy.conf: %s' % open('deploy.conf').read())

    venv_directory = None
    try:
        venv_directory = build_deploy_virtualenv(update_existing=True)
        update_config(venv_directory)
    except:
        print('Unable to create the python virtualenv', file=sys.stderr)
        logger.exception('The virtualenv create failed, removing venv_directory')
        if venv_directory and os.path.exists(venv_directory):
            print('Removing the %r virtualenv directory' % venv_directory)
            shutil.rmtree(venv_directory)
        sys.exit(1)

    try:
        if get_config_flag('global', 'link_bin_files'):
            logger.debug('Linking files in the virtualenv bin directory to %r', os.path.dirname(sys.executable))
            try:
                from invirtualenv.deploy import link_deployed_bin_files
                link_deployed_bin_files(venv_directory, '/usr/bin')