def _create_modified_deployment(self): self.modified_dir = os.path.join(self.workdir, 'modified_blueprint') shutil.copytree(self.repo_dir, self.modified_dir) modified_blueprint_path = util.get_blueprint_path('blueprint.yaml', self.modified_dir) self.modified_blueprint_yaml = \ self._modify_blueprint(modified_blueprint_path) return modified_blueprint_path
def setUp(self, *args, **kwargs): super(ChefPluginClientTest, self).setUp(*args, **kwargs) agent_key_file = get_agent_key_file(self.env) blueprint_dir = self.copy_blueprint('chef-plugin') self.blueprint_yaml = blueprint_dir / 'chef-server-by-chef-solo.yaml' with YamlPatcher(self.blueprint_yaml) as blueprint: bp_info = update_blueprint(self.env, blueprint, 'chef-server') self.chef_server_hostname = bp_info['hostnames'][0] cookbooks_dir = blueprint_dir / 'cookbooks' def run(*args, **kwargs): return subprocess.check_output(*args, **kwargs) with cookbooks_dir: run([ 'wget', '-q', '-O', 'chef-server.zip', CHEF_SERVER_COOKBOOK_ZIP_URL, ]) ZipFile('chef-server.zip').extractall() chef_cookbook_dir = cookbooks_dir.glob('chef-server-*')[0] run(['mv', chef_cookbook_dir, 'chef-server']) # Next line because Chef cookbooks are required # to declare all dependencies, even if they don't use them. # We don't need git, it's only used in chef-cookbook::dev recipe. run(['sed', '-i', "/depends 'git'/d", 'chef-server/metadata.rb']) with blueprint_dir: run(['tar', 'czf', 'cookbooks.tar.gz', 'cookbooks']) self.chef_server_id = self.test_id + '-chef-server' id_ = self.chef_server_id before, after = self.upload_deploy_and_execute_install(id_, id_) fip_node = find_node_state('ip', after['node_state'][id_]) self.chef_server_ip = fip_node['runtimeInfo']['floating_ip_address'] fabric_env = fabric.api.env fabric_env.update({ 'timeout': 30, 'user': bp_info['users'][0], 'key_filename': str(agent_key_file), 'host_string': self.chef_server_ip, }) cookbook_local_path = os.path.abspath( os.path.join(get_blueprint_path('chef-plugin'), 'cookbook-create-file.tar.gz')) setup_chef_server(blueprint_dir, [[ 'create-file', cookbook_local_path, ]]) self.blueprint_dir = blueprint_dir
def test_maintenance_mode(self): self.blueprint_yaml = os.path.join( get_blueprint_path('continous-installation-blueprint'), 'blueprint.yaml' ) self.upload_blueprint(self.test_id) self.create_deployment(self.test_id, self.test_id, inputs={ 'image': self.env.ubuntu_trusty_image_id, 'flavor': self.env.small_flavor_id, 'agent_user': '******' }) # Running not blocking installation execution = self._execute_install() self.logger.info( "checking if maintenance status has status 'deactivated'") self._check_maintenance_status('deactivated') self.logger.info('activating maintenance mode') self.client.maintenance_mode.activate() self.logger.info( "checking if maintenance status has changed to 'activating'") self.repetitive(self._check_maintenance_status, timeout=60, exception_class=AssertionError, args=['activating']) self.logger.info('cancelling installation') self.cfy.cancel_execution(execution['id']) self.logger.info( "checking if maintenance status has changed to 'activated'") self.repetitive(self._check_maintenance_status, timeout=60, exception_class=AssertionError, args=['activated']) self.logger.info('deactivating maintenance mode') self.client.maintenance_mode.deactivate() self.logger.info( "checking if maintenance status has changed to 'deactivated'") self.repetitive(self._check_maintenance_status, timeout=60, exception_class=AssertionError, args=['deactivated']) self.execute_uninstall(self.test_id, self.cfy, True)
def copy_blueprint(self, blueprint_dir_name, blueprints_dir=None): blueprint_path = path(self.workdir) / blueprint_dir_name shutil.copytree(get_blueprint_path(blueprint_dir_name, blueprints_dir), str(blueprint_path)) return blueprint_path
def setUp(self, *args, **kwargs): super(ChefPluginClientTest, self).setUp(*args, **kwargs) agent_key_file = get_actual_keypath(self.env, self.env.agent_key_path) blueprint_dir = self.copy_blueprint('chef-plugin') self.blueprint_yaml = (blueprint_dir / 'chef-server-by-chef-solo-blueprint.yaml') with YamlPatcher(self.blueprint_yaml) as blueprint: bp_info, inputs = update_blueprint(self.env, blueprint, 'chef-server') self.chef_server_hostname = '{0}{1}'.format( self.env.resources_prefix.replace('_', '-'), bp_info['hostnames'][0]) cookbooks_dir = blueprint_dir / 'cookbooks' def run(*args, **kwargs): return subprocess.check_output(*args, **kwargs) with cookbooks_dir: run([ 'wget', '-q', '-O', 'chef-server.zip', CHEF_SERVER_COOKBOOK_ZIP_URL, ]) ZipFile('chef-server.zip').extractall() chef_cookbook_dir = cookbooks_dir.glob('chef-server-*')[0] run(['mv', chef_cookbook_dir, 'chef-server']) # Next line because Chef cookbooks are required # to declare all dependencies, even if they don't use them. # We don't need git, it's only used in chef-cookbook::dev recipe. run(['sed', '-i', "/depends 'git'/d", 'chef-server/metadata.rb']) with blueprint_dir: run(['tar', 'czf', 'cookbooks.tar.gz', 'cookbooks']) self.chef_server_id = self.test_id + '-chef-server' id_ = self.chef_server_id before, after = self.upload_deploy_and_execute_install(id_, id_, inputs=inputs) fip_node = find_node_state('ip', after['node_state'][id_]) self.chef_server_ip = fip_node['runtime_properties'][ 'floating_ip_address'] fabric_env = fabric.api.env fabric_env.update({ 'timeout': 30, 'user': bp_info['users'][0], 'key_filename': str(agent_key_file), 'host_string': self.chef_server_ip, }) cookbook_local_path = os.path.abspath( os.path.join(get_blueprint_path('chef-plugin'), 'cookbook-create-file.tar.gz')) setup_chef_server(blueprint_dir, [[ 'create-file', cookbook_local_path, ]]) self.blueprint_dir = blueprint_dir