def test_create_agent_package_no_cloudify_agent_configured(self):
        config = ap._import_config(CONFIG_FILE)
        del config['cloudify_agent_module']

        e = self.assertRaises(
            SystemExit, ap.create, config, None, force=True, verbose=True)
        self.assertEqual(
            e.message, codes.errors['missing_cloudify_agent_config'])
 def test_create_agent_package_tar_already_exists(self):
     config = ap._import_config(CONFIG_FILE)
     shutil.rmtree(config['venv'])
     with open(config['output_tar'], 'w') as a:
         a.write('CONTENT')
     e = self.assertRaises(
         SystemExit, ap.create, None, CONFIG_FILE, verbose=True)
     self.assertEqual(str(e), '9')
     os.remove(config['output_tar'])
 def test_create_agent_package_tar_already_exists(self):
     config = ap._import_config(CONFIG_FILE)
     shutil.rmtree(TEST_VENV)
     with open(config['output_tar'], 'w') as a:
         a.write('CONTENT')
     e = self.assertRaises(
         SystemExit, ap.create, None, CONFIG_FILE, verbose=True)
     self.assertEqual(e.message, codes.errors['tar_already_exists'])
     os.remove(config['output_tar'])
    def test_create_agent_package_no_cloudify_agent_configured(self):
        config = ap._import_config(CONFIG_FILE)
        del config['cloudify_agent_module']

        e = self.assertRaises(SystemExit,
                              ap.create,
                              config,
                              None,
                              force=True,
                              verbose=True)
        self.assertEqual(e.message,
                         codes.errors['missing_cloudify_agent_config'])
 def test_create_agent_package(self):
     config = ap._import_config(CONFIG_FILE)
     ap.create(None, CONFIG_FILE, force=True, verbose=True)
     if os.path.isdir(config['venv']):
         raise Exception('venv exists before extracting agent.')
     os.makedirs(config['venv'])
     utils.run('tar -xzvf {0} -C {1} --strip-components=2'.format(
         config['output_tar'], BASE_DIR))
     os.remove(config['output_tar'])
     self.assertTrue(os.path.isdir(config['venv']))
     p = utils.run('{0}/bin/pip freeze'.format(config['venv']))
     self.assertIn('cloudify-plugins-common', p.stdout)
     self.assertIn('cloudify-rest-client', p.stdout)
     self.assertIn('cloudify-script-plugin', p.stdout)
     self.assertNotIn('cloudify-diamond-plugin', p.stdout)
     shutil.rmtree(config['venv'])
 def test_create_agent_package_with_version_info(self):
     distro = 'Ubuntu'
     release = 'trusty'
     os.environ['VERSION'] = '3.3.0'
     os.environ['PRERELEASE'] = 'm4'
     os.environ['BUILD'] = '666'
     config = ap._import_config(CONFIG_FILE)
     config.pop('output_tar')
     archive = ap._name_archive(distro, release, os.environ['VERSION'],
                                os.environ['PRERELEASE'],
                                os.environ['BUILD'])
     try:
         ap.create(config, force=True, verbose=True)
         self.assertTrue(os.path.isfile(archive))
     finally:
         os.remove(archive)
         os.environ.pop('VERSION')
         os.environ.pop('PRERELEASE')
         os.environ.pop('BUILD')
 def test_create_agent_package_with_version_info(self):
     distro = 'Ubuntu'
     release = 'trusty'
     os.environ['VERSION'] = '3.3.0'
     os.environ['PRERELEASE'] = 'm4'
     os.environ['BUILD'] = '666'
     config = ap._import_config(CONFIG_FILE)
     config.pop('output_tar')
     archive = ap._name_archive(
         distro, release,
         os.environ['VERSION'],
         os.environ['PRERELEASE'],
         os.environ['BUILD'])
     try:
         ap.create(config, force=True, verbose=True)
         self.assertTrue(os.path.isfile(archive))
     finally:
         os.remove(archive)
         os.environ.pop('VERSION')
         os.environ.pop('PRERELEASE')
         os.environ.pop('BUILD')
 def test_create_agent_package(self):
     cli_options = {
         '--config': CONFIG_FILE,
         '--force': True,
         '--dryrun': False,
         '--no-validation': False,
         '--verbose': True
     }
     required_modules = [
         'cloudify-plugins-common',
         'cloudify-rest-client',
         'cloudify-fabric-plugin',
         'cloudify-agent',
         'pyyaml',
         'xmltodict'
     ]
     excluded_modules = [
         'cloudify-diamond-plugin',
         'cloudify-script-plugin'
     ]
     config = ap._import_config(CONFIG_FILE)
     cli._run(cli_options)
     if os.path.isdir(TEST_VENV):
         shutil.rmtree(TEST_VENV)
     os.makedirs(TEST_VENV)
     utils.run('tar -xzvf {0} -C {1} --strip-components=1'.format(
         config['output_tar'], BASE_DIR))
     os.remove(config['output_tar'])
     self.assertTrue(os.path.isdir(TEST_VENV))
     pip_freeze_output = utils.get_installed(
         TEST_VENV).lower()
     for required_module in required_modules:
         self.assertIn(required_module, pip_freeze_output)
     for excluded_module in excluded_modules:
         self.assertNotIn(excluded_module, pip_freeze_output)
     shutil.rmtree(TEST_VENV)
 def test_import_config_file(self):
     outcome = ap._import_config(CONFIG_FILE)
     self.assertEquals(type(outcome), dict)
     self.assertIn('distribution', outcome.keys())
 def test_import_config_file(self):
     outcome = ap._import_config(CONFIG_FILE)
     self.assertEquals(type(outcome), dict)
     self.assertIn('distribution', outcome.keys())