def test_project(): from burlap import common common.set_verbose(True) try: project_dir = '/tmp/burlap_test'#tempfile.mkdtemp() if not os.path.isdir(project_dir): os.makedirs(project_dir) bin_dir = os.path.split(sys.executable)[0] cmd = ( '. {bin_dir}/activate; ' 'cd {project_dir}; ' 'burlap skel --name=myproject' ).format(**locals()) print(cmd) os.system(cmd) cmd = ( '. {bin_dir}/activate; ' 'cd {project_dir}; ' 'burlap add-role prod dev' ).format(**locals()) print(cmd) os.system(cmd) finally: shutil.rmtree(project_dir) pass
def test_find_template(): from burlap import common common.set_verbose(True) fn = 'burlap/gitignore.template' ret = common.find_template(fn) print('ret:', ret) assert ret and ret.endswith(fn)
def test_jshint1(self): set_verbose(True) jshint.genv.ROLE = 'local' jshint.genv.services = ['jshint'] jshint.clear_caches() # packager.update() # packager.upgrade(full=1) print('Installing jshint...') jshint.env.enabled = True jshint.clear_local_renderer() #jshint.install_packages() # fails on Ubuntu 14 under Travis-CI? #jshint.sudo('apt-get purge nodejs-legacy nodejs') #jshint.sudo('apt-get update --fix-missing; DEBIAN_FRONTEND=noninteractive apt-get -f -o Dpkg::Options::="--force-overwrite" install --yes npm') jshint.configure() deploy_satchel.purge() print('-'*80) print('Thumbprinting...') deploy_satchel.fake(components=jshint.name) print('-'*80) # Confirm jshint was installed. #assert exists('/usr/local/bin/jshint') output = jshint.run('jshint --version') print('output:', output) assert 'jshint v' in output print('Disabling jshint...') jshint.env.enabled = False jshint.clear_local_renderer() jshint.configure()
def test_jshint1(self): set_verbose(True) jshint.genv.ROLE = 'local' jshint.genv.services = ['jshint'] jshint.clear_caches() # packager.update() # packager.upgrade(full=1) print('Installing jshint...') jshint.env.enabled = True jshint.clear_local_renderer() #jshint.install_packages() # fails on Ubuntu 14 under Travis-CI? #jshint.sudo('apt-get purge nodejs-legacy nodejs') #jshint.sudo('apt-get update --fix-missing; DEBIAN_FRONTEND=noninteractive apt-get -f -o Dpkg::Options::="--force-overwrite" install --yes npm') jshint.configure() deploy_satchel.purge() print('-' * 80) print('Thumbprinting...') deploy_satchel.fake(components=jshint.name) print('-' * 80) # Confirm jshint was installed. #assert exists('/usr/local/bin/jshint') output = jshint.run('jshint --version') print('output:', output) assert 'jshint v' in output print('Disabling jshint...') jshint.env.enabled = False jshint.clear_local_renderer() jshint.configure()
def run(self, *args, **kwargs): from burlap.common import set_dryrun, set_verbose if 'dryrun' in kwargs: set_dryrun(kwargs['dryrun']) del kwargs['dryrun'] if 'verbose' in kwargs: set_verbose(kwargs['verbose']) del kwargs['verbose'] return self.wrapped(*args, **kwargs)
def setUp(self): super(DebugTests, self).setUp() common.set_verbose(True) # Ensure we're in burlap's root directory. os.chdir(os.path.abspath(os.path.join(CURRENT_DIR, '../..'))) self._tmp_host_string = common.env.host_string self._tmp_is_local = common.env.is_local common.env.host_string = 'localhost' common.env.is_local = True
def test_post_deploy(self): with patch('burlap.common.get_os_version') as mock_get_os_version: mock_get_os_version.return_value = OS(type=LINUX, distro=UBUNTU, release='16.04') service = get_satchel('service') apache = get_satchel('apache') service.genv.services.append(apache.name) set_verbose(1) set_dryrun(1) print('self.genv.services:', service.genv.services) service.post_deploy()
def test_render_to_string(): from burlap import common common.set_verbose(True) ret = common.render_to_string( 'postfix/etc_postfix_sasl_sasl_passwd', dict( postfix_host='smpt.test.com', postfix_port=1234, postfix_username='******', postfix_password='******', )) print('ret:', ret) assert ret == "[smpt.test.com]:1234 myusername:mypassword"
def test_post_deploy(self): with patch('burlap.common.get_os_version') as mock_get_os_version: mock_get_os_version.return_value = OS( type=LINUX, distro=UBUNTU, release='16.04') service = get_satchel('service') apache = get_satchel('apache') service.genv.services.append(apache.name) set_verbose(1) set_dryrun(1) print('self.genv.services:', service.genv.services) service.post_deploy()
def tearDown(self): set_dryrun(self._dryrun) set_verbose(self._verbose) # Restore CWD. os.chdir(self._cwd) # Restore fabric state. self.clear_env() self.update_env(self._env) # Restore burlap state. clear_state() set_state(self._burlap_state) super(TestCase, self).tearDown()
def test_hooks(self): set_verbose(True) git.genv.ROLE = 'prod' git.genv.services = ['git'] git.clear_caches() print('Installing git...') git.install_packages() # fails on Ubuntu 14 under Travis-CI? print('Setting up sample git repo...') run('mkdir /tmp/mygithookrepo || true') with cd('/tmp/mygithookrepo'): run('git init') assert not exists('/tmp/mygithookrepo/.git/hooks/post-checkout') print('Configuring git...') git.env.enabled = True git.env.hooks = {'/tmp/mygithookrepo': ['git/post-checkout']} git.clear_local_renderer() deploy_satchel.purge() cm = git.current_manifest print('cm1:', cm) assert 'hooks' in cm added_hooks, removed_hooks = git.get_changed_hooks() print('added_hooks:', added_hooks) assert added_hooks == {'/tmp/mygithookrepo': ['git/post-checkout']} print('removed_hooks:', removed_hooks) assert removed_hooks == {} print('Installing git hooks...') git.clear_local_renderer() git.configure() deploy_satchel.purge() print('-'*80) print('Thumbprinting...') #thumbprint(components=git.name) deploy_satchel.fake(components=git.name) print('-'*80) assert exists('/tmp/mygithookrepo/.git/hooks/post-checkout')
def test_hooks(self): set_verbose(True) git.genv.ROLE = 'prod' git.genv.services = ['git'] git.clear_caches() print('Installing git...') git.install_packages() # fails on Ubuntu 14 under Travis-CI? print('Setting up sample git repo...') run('mkdir /tmp/mygithookrepo || true') with cd('/tmp/mygithookrepo'): run('git init') assert not exists('/tmp/mygithookrepo/.git/hooks/post-checkout') print('Configuring git...') git.env.enabled = True git.env.hooks = {'/tmp/mygithookrepo': ['git/post-checkout']} git.clear_local_renderer() deploy_satchel.purge() cm = git.current_manifest print('cm1:', cm) assert 'hooks' in cm added_hooks, removed_hooks = git.get_changed_hooks() print('added_hooks:', added_hooks) assert added_hooks == {'/tmp/mygithookrepo': ['git/post-checkout']} print('removed_hooks:', removed_hooks) assert removed_hooks == {} print('Installing git hooks...') git.clear_local_renderer() git.configure() deploy_satchel.purge() print('-' * 80) print('Thumbprinting...') #thumbprint(components=git.name) deploy_satchel.fake(components=git.name) print('-' * 80) assert exists('/tmp/mygithookrepo/.git/hooks/post-checkout')
def test_set_verbose(self): from burlap.common import set_verbose, get_verbose set_verbose(True) assert get_verbose() set_verbose(False) assert not get_verbose() set_verbose(1) assert get_verbose() set_verbose(0) assert not get_verbose()
def test_project(): from burlap import common common.set_verbose(True) try: project_dir = '/tmp/burlap_test' #tempfile.mkdtemp() if not os.path.isdir(project_dir): os.makedirs(project_dir) bin_dir = os.path.split(sys.executable)[0] cmd = ('. {bin_dir}/activate; ' 'cd {project_dir}; ' 'burlap skel --name=myproject').format(**locals()) print(cmd) os.system(cmd) cmd = ('. {bin_dir}/activate; ' 'cd {project_dir}; ' 'burlap add-role prod dev').format(**locals()) print(cmd) os.system(cmd) finally: shutil.rmtree(project_dir) pass
def setUp(self): super(ProjectTests, self).setUp() set_verbose(True) # Ensure we're in burlap's root directory. os.chdir(os.path.abspath(os.path.join(CURRENT_DIR, '../..')))
def _test_deploy(self): """ Creates a multi-site Apache Django powered web server with a MySQL backend. """ try: set_verbose(True) assert 'apache_specifics' in env print('all_satchels:', sorted(all_satchels.keys())) assert len(all_satchels.keys()) == 61 print('env.host_string:', env.host_string) print('env.hosts:', env.hosts) print('env.user:'******'/tmp/burlap_test' if os.path.exists(PROJECT_DIR): #shutil.rmtree(PROJECT_DIR) os.system('rm -Rf %s/*' % PROJECT_DIR) else: os.makedirs(PROJECT_DIR) # Create our test virtualenv. PYTHON_EXE = os.path.split(sys.executable)[-1] VIRTUALENV_DIR = os.path.join(PROJECT_DIR, '.env') BURLAP_DIR = os.path.abspath(os.path.join(BASE_DIR, 'burlap')) BURLAP_BIN = os.path.abspath( os.path.join(BASE_DIR, 'bin/burlap-admin.py')) SITE_PACKAGES = os.path.join(VIRTUALENV_DIR, 'lib/%s/site-packages' % PYTHON_EXE) # Initialize project. kwargs = dict( project_dir=PROJECT_DIR, burlap_bin=BURLAP_BIN, ) print('Initializing project skeleton...') assert os.path.isdir(PROJECT_DIR) with set_cwd(PROJECT_DIR): _status, _output = self.bash( '{burlap_bin} skel multitenant'.format(**kwargs)) print('_status, _output:', _status, _output) assert not _status # Symlink burlap. _status, _output = self.bash('ln -s %s %s' % (BURLAP_DIR, SITE_PACKAGES)) #assert not _status # Add production role. VIRTUALENV_ACTIVATE = '. %s/bin/activate' % VIRTUALENV_DIR kwargs = dict( project_dir=PROJECT_DIR, activate=VIRTUALENV_ACTIVATE, burlap_bin=BURLAP_BIN, ) assert os.path.isdir(PROJECT_DIR) _status, _output = self.bash( '{burlap_bin} add-role prod'.format(**kwargs)) assert not _status # Test logging in to VM. print('env.host_string:', env.host_string) print('env.user:'******'env.key_filename:', env.key_filename) env.ROLE = 'prod' prod_settings = Shelf( filename='%s/roles/{role}/settings.yaml' % PROJECT_DIR) prod_settings['hosts'] = [env.host_string] assert prod_settings['hosts'][0] #prod_settings['host_string'] prod_settings['user'] = env.user prod_settings['key_filename'] = env.key_filename prod_settings['is_local'] = False prod_settings['app_name'] = 'multitenant' kwargs = dict(project_dir=PROJECT_DIR, ) self.bash('ls -lah .') assert os.path.isdir(PROJECT_DIR) print('Testing hello world...') _status, _output = self.bash( '.env/bin/fab prod:verbose=1 shell:command="echo hello"'. format(**kwargs)) print('_status, _output:', _status, _output) assert not _status _status, _output = self.bash('ls -lah .') print('_status, _output:', _status, _output) print('Testing ifconfig...') _status, _output = self.bash( '.env/bin/fab prod:verbose=1 shell:command="ifconfig"'. format(**kwargs)) print('_status, _output:', _status, _output) assert 'inet addr:127.0.0.1' in _output # Add services. services = prod_settings.get('services', []) services.extend([ 'apache', #'hostname', 'mysql', 'mysqlclient', 'ntpclient', 'packager', 'pip', 'sshnice', 'tarball', 'timezone', 'ubuntumultiverse', 'unattendedupgrades', #'user', ]) prod_settings.set('services', services) prod_settings.set( 'sites', { 'multitenant': { 'apache_domain_template': 'multitenant.test.com', 'apache_domain_with_sub_template': 'multitenant.test.com', 'apache_domain_without_sub_template': 'multitenant.test.com', 'apache_server_aliases_template': 'multitenant.test.com', 'apache_ssl': False, 'apache_auth_basic': False, 'apache_enforce_subdomain': False, }, }) prod_settings.set('pip_requirements', 'pip-requirements.txt') prod_settings.set('packager_initial_upgrade', False) # Confirm deployment changes are detected. #from burlap import role_prod as prod prod = load_role_handler('prod') prod() assert 'app_name' in env assert 'sites' in env env.host_string = env.hosts[0] print('-' * 80) set_verbose(1) assert 'apache_specifics' in env print('Getting changed_components.verbose:', get_verbose()) changed_components, deploy_funcs = deploy_satchel.get_component_funcs( ) changed_components = sorted(changed_components) expected_components = [ 'APACHE', 'MYSQL', 'MYSQLCLIENT', 'NTPCLIENT', 'PACKAGER', 'PIP', 'SSHNICE', 'TARBALL', 'TIMEZONE', 'UBUNTUMULTIVERSE', 'UNATTENDEDUPGRADES', ] print('changed_components:', changed_components) print('expected_components:', expected_components) assert changed_components == expected_components deploy_funcs = sorted(deploy_funcs) print('deploy_funcs:', deploy_funcs) assert deploy_funcs == [ ('apache.configure', None), ('mysql.configure', None), ('mysqlclient.configure', None), ('ntpclient.configure', None), ('packager.configure', None), ('pip.configure', None), ('sshnice.configure', None), ('tarball.configure', None), ('timezone.configure', None), ('ubuntumultiverse.configure', None), ('unattendedupgrades.configure', None), ] # Deploy changes. # Confirm changes have been cleared. # Add Django site. finally: # Undo changes to the VM. pass
def test_selenium(self): try: print('deploy_satchel.env.lockfile_path:', deploy_satchel.env.lockfile_path) print('deploy_satchel.env.data_dir:', deploy_satchel.env.data_dir) assert deploy_satchel.env.lockfile_path == '/tmp/burlap_unittests/deploy.lock' assert deploy_satchel.env.data_dir == '/tmp/burlap_unittests' assert deploy_satchel.manifest_filename == '/tmp/burlap_unittests/manifest.yaml' set_verbose(True) print('selenium.geckodriver_path:', selenium.geckodriver_path) selenium.genv.ROLE = 'local' selenium.genv.services = ['selenium'] selenium.clear_caches() print('Enabling selenium/gecko to install and track old version.') print('selenium._last_manifest.1:', selenium._last_manifest) print('selenium.last_manifest.1:', selenium.last_manifest) selenium.env.enabled = True selenium.env.geckodriver_version = '0.13.0' selenium.clear_local_renderer() assert selenium.get_target_geckodriver_version_number() == '0.13.0' print('Configuring selenium...') selenium.configure() print('selenium._last_manifest.2:', selenium._last_manifest) print('selenium.last_manifest.2:', selenium.last_manifest) print('Writing manifest...') deploy_satchel.fake(components=selenium.name) deploy_satchel.run('ls -lah %s' % deploy_satchel.manifest_filename) deploy_satchel.run('cat %s' % deploy_satchel.manifest_filename) print('selenium._last_manifest.3:', selenium._last_manifest) print('selenium.last_manifest.3:', selenium.last_manifest) print('Confirming install succeeded...') assert exists(selenium.geckodriver_path) assert not selenium.check_for_change() output = selenium.run('geckodriver --version') print('Geckodriver version:', output) expected_version = selenium.env.geckodriver_version assert expected_version in output print('Updating configuration to track the most recent version...') selenium.env.geckodriver_version = None selenium.clear_local_renderer() assert selenium.get_target_geckodriver_version_number() != '0.13.0' assert selenium.last_manifest.fingerprint == '0.13.0' print('Confirm we now see a pending change...') assert selenium.check_for_change() print('-'*80) print('Applying change...') selenium.configure() deploy_satchel.purge() print('-'*80) print('Thumbprinting...') deploy_satchel.fake(components=selenium.name) print('-'*80) print('Confirming the most recent version was installed...') expected_version = selenium.get_most_recent_version() selenium.clear_caches() assert selenium.last_manifest.fingerprint == expected_version output = selenium.run('geckodriver --version') expected_version = selenium.get_latest_geckodriver_version_number() assert expected_version in output assert not selenium.check_for_change() print('Update configuration to not manage gecko and apply...') selenium.env.enabled = False selenium.clear_local_renderer() selenium.configure() # Confirm gecko was uninstalled. assert not exists(selenium.geckodriver_path) finally: selenium.uninstall_geckodriver()