def _test_nodecellar_impl(self, blueprint_file): self.repo_dir = clone(self.repo_url, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_file self.modify_blueprint() before_install, after_install = self.upload_deploy_and_execute_install( inputs=self.get_inputs()) self.post_install_assertions(before_install, after_install) self.kill_nodejs_vm() # make sure nodecellar is down self.assert_nodecellar_down(self.public_ip) self.wait_for_autoheal(after_install) after_autoheal = self.get_manager_state() self.post_autoheal_assertions(after_install, after_autoheal) self.execute_uninstall() self.post_uninstall_assertions()
def bootstrap_simple_manager_blueprint(self): self.manager_blueprints_repo_dir = clone(MANAGER_BLUEPRINTS_REPO_URL, self.workdir) self.test_manager_blueprint_path = \ os.path.join(self.manager_blueprints_repo_dir, 'simple', 'simple-manager-blueprint.yaml') # using the updated handler configuration blueprint to update the # package urls in the simple manager blueprint self._update_manager_blueprint() self.bootstrap_inputs = { 'public_ip': self.public_ip_address, 'private_ip': self.private_ip_address, 'ssh_user': '******', 'ssh_key_filename': self.inputs['key_pair_path'], 'agents_user': '******', 'resources_prefix': '' } # preparing inputs file for bootstrap self.test_inputs_path = \ self.cfy._get_inputs_in_temp_file(self.bootstrap_inputs, self._testMethodName) self._bootstrap() self._running_env_setup(self.public_ip_address)
def _prepare_manager_blueprint(self, version): blueprints_repo_path = clone(BLUEPRINTS_REPO, self._get_manager_dir(version), version) if version == V3_2_1: blueprint_path = os.path.join(blueprints_repo_path, 'openstack', 'openstack-manager-blueprint.yaml') else: blueprint_path = os.path.join(blueprints_repo_path, 'openstack-manager-blueprint.yaml') external_resources = [ 'node_templates.management_network.properties', 'node_templates.management_subnet.properties', 'node_templates.router.properties', 'node_templates.agents_security_group.properties', 'node_templates.management_security_group.properties', ] with YamlPatcher(blueprint_path) as patch: patch.merge_obj( 'node_templates.management_subnet.properties.subnet', {'dns_nameservers': ['8.8.8.8', '8.8.4.4']} ) for prop in external_resources: patch.merge_obj(prop, {'use_external_resource': True}) return blueprint_path
def bootstrap_simple_manager_blueprint(self): self.manager_blueprints_repo_dir = clone(MANAGER_BLUEPRINTS_REPO_URL, self.workdir) self.test_manager_blueprint_path = \ os.path.join(self.manager_blueprints_repo_dir, 'new', 'simple-manager-blueprint.yaml') self.bootstrap_inputs = { 'public_ip': self.public_ip_address, 'private_ip': self.private_ip_address, 'ssh_user': self.env.centos_7_image_user, 'ssh_key_filename': self.inputs['key_pair_path'], 'agents_user': self.env.centos_7_image_user, 'resources_prefix': '' } # preparing inputs file for bootstrap self.test_inputs_path = \ self.cfy._get_inputs_in_temp_file(self.bootstrap_inputs, self._testMethodName) self._bootstrap() self._running_env_setup(self.public_ip_address) self.logger.info('Uploading key file to manager...') with fabric_api.settings(host_string=self.public_ip_address, user=self.env.centos_7_image_user, key_filename=self.inputs['key_pair_path']): fabric_api.put(self.inputs['key_pair_path'], self.remote_manager_key_path)
def _run(self, image_name, user, is_existing_deployment=False): if not is_existing_deployment: self.repo_dir = clone(CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, self.workdir) self.blueprint_path = self.repo_dir / 'hello-world' self.blueprint_yaml = self.blueprint_path / 'blueprint.yaml' self.upload_deploy_and_execute_install( fetch_state=False, inputs=dict( agent_user=user, image_name=image_name, flavor_name=self.env.flavor_name)) else: self.execute_install(deployment_id=self.test_id, fetch_state=False) # We assert for events to test events are actually # sent in a real world environment. # This is the only test that needs to make this assertion. self.assert_events() floating_ip_id, neutron, nova, sg_id, server_id =\ self._verify_deployment_installed() self._uninstall_and_make_assertions(floating_ip_id, neutron, nova, sg_id, server_id)
def _test_nodecellar_impl(self, blueprint_file): self.repo_dir = clone(self.repo_url, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_file self.modify_blueprint() before_install, after_install = self.upload_deploy_and_execute_install( inputs=self.get_inputs() ) self.post_install_assertions(before_install, after_install) self.kill_nodejs_vm() # make sure nodecellar is down self.assert_nodecellar_down(self.public_ip) self.wait_for_autoheal(after_install) after_autoheal = self.get_manager_state() self.post_autoheal_assertions(after_install, after_autoheal) self.execute_uninstall() self.post_uninstall_assertions()
def test_resources_available(self): blueprint_name = 'openstack-blueprint.yaml' self.repo_dir = clone(self.repo_url, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_name self.upload_blueprint(self.test_id) invalid_resource_url = 'http://{0}/resources/blueprints/{1}/{2}' \ .format(self.env.management_ip, self.test_id, blueprint_name) try: result = requests.head(invalid_resource_url) self.assertNotEqual( result.status_code, 200, "Resources are available through a different port than 53229.") except ConnectionError: pass valid_resource_url = 'http://{0}:53229/blueprints/{1}/{2}' \ .format(self.env.management_ip, self.test_id, blueprint_name) try: result = requests.head(valid_resource_url) self.assertEqual( result.status_code, 200, "Resources are not available through the port 53229.") except ConnectionError: self.fail("Resources are not available through the port 53229.") self.cfy.delete_blueprint(self.test_id)
def _install_hello_world(self, version): manager_dir = self._get_manager_dir(version) hello_repo_dir = clone(HELLO_WORLD_REPO, manager_dir, version) hello_blueprint_path = os.path.join(hello_repo_dir, 'blueprint.yaml') with YamlPatcher(hello_blueprint_path) as patch: patch.merge_obj( 'node_templates.security_group.interfaces', {'cloudify.interfaces.lifecycle': { 'create': { 'inputs': { 'args': {'description': 'hello security group'} } } }} ) arguments = { 'manager_dir': manager_dir, 'activate_path': os.path.join(self._get_activate_path(version)), 'hello_blueprint_path': hello_blueprint_path, 'inputs_path': self._prepare_hello_world_inputs() } self._run_script('install_hello_world.sh', arguments)
def deploy_hello_world(self, prefix=''): """Install the hello world app.""" blueprint_id = prefix + self.test_id deployment_id = prefix + self.test_id hello_repo_dir = tempfile.mkdtemp(prefix='manager-upgrade-') hello_repo_path = clone( 'https://github.com/cloudify-cosmo/' 'cloudify-hello-world-example.git', hello_repo_dir ) self.addCleanup(shutil.rmtree, hello_repo_dir) hello_blueprint_path = hello_repo_path / 'blueprint.yaml' self.cfy.blueprints.upload( hello_blueprint_path, blueprint_id=blueprint_id ) inputs = { 'agent_user': self.env.ubuntu_image_user, 'image': self.env.ubuntu_trusty_image_name, 'flavor': self.env.flavor_name } inputs = self.get_inputs_in_temp_file(inputs, deployment_id) self.manager_cfy.deployments.create( deployment_id, blueprint_id=blueprint_id, inputs=inputs ) self.manager_cfy.executions.start( 'install', deployment_id=deployment_id ) return deployment_id
def bootstrap_simple_manager_blueprint(self, override_inputs=None): self.manager_blueprints_repo_dir = clone(MANAGER_BLUEPRINTS_REPO_URL, self.workdir) self.test_manager_blueprint_path = \ os.path.join(self.manager_blueprints_repo_dir, 'simple-manager-blueprint.yaml') self.bootstrap_inputs = { 'public_ip': self.public_ip_address, 'private_ip': self.private_ip_address, 'ssh_user': self.env.centos_7_image_user, 'ssh_key_filename': self.inputs['key_pair_path'], 'agents_user': self.env.centos_7_image_user, 'resources_prefix': '' } if override_inputs is not None: self.bootstrap_inputs.update(override_inputs) # preparing inputs file for bootstrap self.test_inputs_path = \ self.cfy._get_inputs_in_temp_file(self.bootstrap_inputs, self._testMethodName) self._bootstrap() self._running_env_setup(self.public_ip_address) self.logger.info('Uploading key file to manager...') with fabric_api.settings(host_string=self.public_ip_address, user=self.env.centos_7_image_user, key_filename=self.inputs['key_pair_path']): fabric_api.put(self.inputs['key_pair_path'], self.remote_manager_key_path)
def _run(self, image_name, user, is_existing_deployment=False): if not is_existing_deployment: self.repo_dir = clone(CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, self.workdir) self.blueprint_yaml = self.repo_dir / 'blueprint.yaml' self.upload_deploy_and_execute_install( fetch_state=False, inputs=dict( agent_user=user, image=image_name, flavor=self.env.flavor_name)) else: self.execute_install(deployment_id=self.test_id, fetch_state=False) # We assert for events to test events are actually # sent in a real world environment. # This is the only test that needs to make this assertion. self.assert_events() floating_ip_id, neutron, nova, sg_id, server_id =\ self._verify_deployment_installed() self.assert_deployment_monitoring_data_exists() floating_ip = neutron.show_floatingip(floating_ip_id) ip = floating_ip['floatingip']['floating_ip_address'] web_server_node = get_web_server_node(self.client, self.test_id) port = web_server_node.properties['port'] expected_output = \ {u'http_endpoint': u'http://{0}:{1}'.format(ip, port)} self.assert_outputs(expected_output) self._uninstall_and_make_assertions(floating_ip_id, neutron, nova, sg_id, server_id)
def _install_hello_world_on_3_2_1(self): self.logger.info('Installing HelloWorld application on manager 3.2.1') # generate inputs file inputs_template_vars = { 'agent_user': self.env.cloudify_agent_user, 'image': self.env.ubuntu_trusty_image_name, 'flavor': self.env.flavor_name } self._render_script( HELLOWORLD_TEMPLATE_NAME, inputs_template_vars, HELLOWORLD_INPUTS_NAME ) hello_repo_path = clone( 'https://github.com/cloudify-cosmo/' 'cloudify-hello-world-example.git', self.workdir, '3.2.1-build' ) hello_blueprint_path = os.path.join(hello_repo_path, 'blueprint.yaml') with YamlPatcher(hello_blueprint_path) as patch: patch.merge_obj( 'node_templates.security_group.interfaces', {'cloudify.interfaces.lifecycle': { 'create': { 'inputs': { 'args': {'description': 'hello security group'} } } }} ) template_vars = { 'work_dir': self.workdir, 'venv_name': VIRTUALENV_NAME, 'repo_path': hello_repo_path, 'helloworld_inputs_file': HELLOWORLD_INPUTS_NAME, 'app_name': HELLOWORLD_APP_NAME, 'runtime_property_name': RUNTIME_PROPERTY_NAME, 'runtime_property_value': self.runtime_property_value } self._render_script( INSTALL_TEMPLATE_NAME, template_vars, INSTALL_SCRIPT_NAME ) rc = self._run_script(INSTALL_SCRIPT_NAME) if rc: self.fail( 'Installing HelloWorld application on manager 3.2.1 failed ' 'with exit code: {0}'.format(rc) )
def get_upgrade_blueprint(self): repo_dir = tempfile.mkdtemp(prefix='manager-upgrade-') self.addCleanup(shutil.rmtree, repo_dir) upgrade_blueprint_path = clone(UPGRADE_REPO_URL, repo_dir, branch=UPGRADE_BRANCH) return upgrade_blueprint_path / 'simple-manager-blueprint.yaml'
def get_simple_blueprint(self): """Blueprint to run the upgrade with. We use the simple blueprint for upgrading the manager, no matter which blueprint was originally used for bootstrapping. """ blueprint_dir = clone(UPGRADE_REPO_URL, self.workdir, branch=UPGRADE_BRANCH) blueprint_path = (blueprint_dir / 'simple-manager-blueprint.yaml') self.addCleanup(shutil.rmtree, blueprint_dir) return blueprint_path
def _get_marketplace_image_bakery_repo(self): self.base_temp_dir = tempfile.mkdtemp() url = self.env.cloudify_config.get( 'image_bakery_url', DEFAULT_IMAGE_BAKERY_REPO_URL ) git.clone( url=url, basedir=self.base_temp_dir, branch=self.env.cloudify_config.get('image_bakery_branch'), ) self.addCleanup(self.clean_temp_dir) repo_path = os.path.join( self.base_temp_dir, 'git', 'cloudify-image-bakery', ) return repo_path
def test_two_deployments(self): repo_dir = clone(bash.CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, self.workdir) self.blueprint_path = repo_dir self.blueprint_yaml = self.blueprint_path / 'blueprint.yaml' count = 2 deployments = [self.Deployment(self, i) for i in range(count)] for deployment in deployments: deployment.run() for deployment in deployments: deployment.wait_for()
def test_two_deployments(self): repo_dir = clone(bash.CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, self.workdir) self.blueprint_path = repo_dir / 'hello-world' self.blueprint_yaml = self.blueprint_path / 'blueprint.yaml' count = 2 deployments = [self.Deployment(self, i) for i in range(count)] for deployment in deployments: deployment.run() for deployment in deployments: deployment.wait_for()
def get_upgrade_blueprint(self): """Path to the blueprint using for upgrading the manager. Note that upgrade uses a simple blueprint, even though the manager was installed using the openstack blueprint. Upgrade does not need to use the same blueprint. """ repo_dir = tempfile.mkdtemp(prefix='manager-upgrade-') self.addCleanup(shutil.rmtree, repo_dir) upgrade_blueprint_path = clone(UPGRADE_REPO_URL, repo_dir, branch=UPGRADE_BRANCH) return upgrade_blueprint_path / 'simple-manager-blueprint.yaml'
def setUp(self): super(HelloWorldSnapshotMigrationFrom_3_2_1_To_3_3_Test, self).setUp() try: self.manager_3_2_1_ip = \ self.env.handler_configuration['manager_3_2_1_ip'] msg = "In case of using existing 3.2.1 manager, providing '{0}' " \ "is also required." try: self.manager_cred_path = \ self.env.handler_configuration[ 'manager_3_2_1_credentials_path' ] except KeyError as e: self.fail(msg.format(e.args[0])) self.bootstrap_managers = False if not self.env.management_ip: self.fail('Manager 3.3 is required to be bootstrapped in case' 'of using existing manager 3.2.1.') except KeyError: self.manager_3_2_1_ip = None self.bootstrap_managers = True self.snapshot = None self.manager_public_key_name = self.test_id + '-manager-kp' self.agent_public_key_name = self.test_id + '-agents-kp' self.manager_key_path = os.path.join(self.workdir, MANAGER_KEY_FILE_NAME) self.agents_key_path = os.path.join(self.workdir, AGENTS_KEY_FILE_NAME) self.management_network_name = self.test_id + '-network' self.management_subnet_name = self.test_id + '-subnet' self.management_router = self.test_id + '-router' self.agents_user = '******' self.repo_path = clone( 'https://github.com/cloudify-cosmo/' 'cloudify-manager-blueprints.git', self.workdir, '3.3' ) self.runtime_property_value = self.test_id + '-runtime-property'
def _test_nodecellar_impl(self, blueprint_file): self.repo_dir = clone(self.repo_url, self.workdir, self.repo_branch) self.blueprint_yaml = self.repo_dir / blueprint_file self.modify_blueprint() before, after = self.upload_deploy_and_execute_install( inputs=self.get_inputs() ) self.post_install_assertions(before, after) self.execute_uninstall() self.post_uninstall_assertions()
def clone_example(self): if not self._cloned_to: # Destination will be e.g. # /tmp/pytest_generated_tempdir_for_test_1/examples/bootstrap_ssl/ destination = os.path.join( str(self.tmpdir), 'examples', self.suffix, ) self.branch = self.branch or os.environ.get( 'BRANCH_NAME_CORE', git_helper.MASTER_BRANCH) self._cloned_to = git_helper.clone(self.REPOSITORY_URL, destination, self.branch)
def _test_nodecellar_impl(self, blueprint_file, execute_timeout=DEFAULT_EXECUTE_TIMEOUT): self.repo_dir = clone(self.repo_url, self.workdir, self.repo_branch) self.blueprint_yaml = self.repo_dir / blueprint_file self.modify_blueprint() before, after = self.upload_deploy_and_execute_install( inputs=self.get_inputs(), execute_timeout=execute_timeout ) self.post_install_assertions(before, after) self.execute_uninstall() self.post_uninstall_assertions()
def clone_example(self): if not self._cloned_to: # Destination will be e.g. # /tmp/pytest_generated_tempdir_for_test_1/examples/bootstrap_ssl/ destination = os.path.join( str(self.tmpdir), 'examples', self.suffix, ) self.branch = self.branch or os.environ.get( 'BRANCH_NAME_CORE', git_helper.MASTER_BRANCH) self._cloned_to = git_helper.clone(self.REPOSITORY_URL, destination, self.branch)
def _create_and_download_snapshot(self, version): manager_dir = self._get_manager_dir(version) arguments = { 'manager_dir': self._get_manager_dir(version), 'activate_path': os.path.join( self._get_activate_path(version)), 'snapshot_path': self._get_snapshots_path(version) } if version == V3_2_1: arguments['snapshot_tool_dir'] = clone(SNAPSHOT_TOOL_REPO, manager_dir) self._run_script('download_snapshot_321.sh', arguments) else: self._run_script('download_snapshot_33plus.sh', arguments)
def setUp(self): super(HelloWorldSnapshotMigrationFrom_3_2_1_To_3_3_Test, self).setUp() try: self.manager_3_2_1_ip = \ self.env.handler_configuration['manager_3_2_1_ip'] msg = "In case of using existing 3.2.1 manager, providing '{0}' " \ "is also required." try: self.manager_cred_path = \ self.env.handler_configuration[ 'manager_3_2_1_credentials_path' ] except KeyError as e: self.fail(msg.format(e.args[0])) self.bootstrap_managers = False if not self.env.management_ip: self.fail('Manager 3.3 is required to be bootstrapped in case' 'of using existing manager 3.2.1.') except KeyError: self.manager_3_2_1_ip = None self.bootstrap_managers = True self.snapshot = None self.manager_public_key_name = self.test_id + '-manager-kp' self.agent_public_key_name = self.test_id + '-agents-kp' self.manager_key_path = os.path.join(self.workdir, MANAGER_KEY_FILE_NAME) self.agents_key_path = os.path.join(self.workdir, AGENTS_KEY_FILE_NAME) self.management_network_name = self.test_id + '-network' self.management_subnet_name = self.test_id + '-subnet' self.management_router = self.test_id + '-router' self.agents_user = '******' self.repo_path = clone( 'https://github.com/cloudify-cosmo/' 'cloudify-manager-blueprints.git', self.workdir, '3.3') self.runtime_property_value = self.test_id + '-runtime-property'
def _bootstrap_manager(self, version): manager_dir = self._get_manager_dir(version) cli_repo_dir = clone(CLI_REPO, manager_dir, version) blueprint_path = self._prepare_manager_blueprint(version) arguments = { 'manager_dir': manager_dir, 'venv_dir': self._get_venv_dir(version), 'activate_path': self._get_activate_path(version), 'cli_repo_dir': cli_repo_dir, 'cli_requirements_path': os.path.join(cli_repo_dir, 'dev-requirements.txt'), 'blueprint_path': blueprint_path, 'inputs_path': self._prepare_manager_inputs( os.path.dirname(blueprint_path), version) } self._run_script('bootstrap_manager.sh', arguments)
def _test_nodecellar_impl(self, blueprint_file): self.addCleanup(self._test_cleanup) self.repo_dir = clone(self.repo_url, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_file # install before_install, after_install = self.upload_deploy_and_execute_install( inputs=self.get_inputs()) self.post_install_assertions(before_install, after_install) # scale out (+1) self._scale(delta=1) self.post_scale_assertions(expected_instances=3) # scale in (-2) self._scale(delta=-2) self.post_scale_assertions(expected_instances=1) # uninstall self.execute_uninstall() self.post_uninstall_assertions()
def _test_nodecellar_impl(self, blueprint_file): self.addCleanup(self._test_cleanup) self.repo_dir = clone(self.repo_url, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_file # install before_install, after_install = self.upload_deploy_and_execute_install( inputs=self.get_inputs()) self.post_install_assertions(before_install, after_install) # scale out (+1) self._scale(delta=1) self.post_scale_assertions(expected_instances=3) # scale in (-2) self._scale(delta=-2) self.post_scale_assertions(expected_instances=1) # uninstall self.execute_uninstall() self.post_uninstall_assertions()
def _run(self, inputs=None, blueprint_file='blueprint.yaml', is_existing_deployment=False, influx_host_ip=None): if not is_existing_deployment: self.repo_dir = clone(CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, self.workdir) self.blueprint_yaml = self.repo_dir / blueprint_file self.upload_deploy_and_execute_install( fetch_state=False, inputs=inputs) else: self.execute_install(deployment_id=self.test_id, fetch_state=False) # We assert for events to test events are actually # sent in a real world environment. # This is the only test that needs to make this assertion. self.logger.info('Asserting events...') self.assert_events() outputs = self.client.deployments.outputs.get(self.test_id)['outputs'] self.logger.info('Deployment outputs: {0}'.format(outputs)) self.logger.info('Verifying web server is running on: {0}'.format( outputs['http_endpoint'])) verify_webserver_running(outputs['http_endpoint']) self.logger.info('Performing post install assertions...') context = self._do_post_install_assertions() self.logger.info('Asserting deployment monitoring data exists...') self.assert_deployment_monitoring_data_exists( influx_host_ip=influx_host_ip) self.logger.info('Uninstalling deployment...') self.execute_uninstall() self.logger.info('Performing post uninstall assertions...') self._do_post_uninstall_assertions(context)
def get_bootstrap_blueprint(self): manager_repo_dir = tempfile.mkdtemp(prefix='manager-upgrade-') self.addCleanup(shutil.rmtree, manager_repo_dir) manager_repo = clone(BOOTSTRAP_REPO_URL, manager_repo_dir, branch=BOOTSTRAP_BRANCH) yaml_path = manager_repo / 'openstack-manager-blueprint.yaml' # allow the ports that we're going to connect to from the tests, # when doing checks for port in [8086, 9200, 9900]: secgroup_cfg = [{ 'port_range_min': port, 'port_range_max': port, 'remote_ip_prefix': '0.0.0.0/0' }] secgroup_cfg_path = 'node_templates.management_security_group' \ '.properties.rules' with YamlPatcher(yaml_path) as patch: patch.append_value(secgroup_cfg_path, secgroup_cfg) return yaml_path
def clone_hello_world(workdir): return clone(CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, workdir)
def _clone_manager_blueprints(self): self._manager_blueprints_path = git_helper.clone( MANAGER_BLUEPRINTS_REPO_URL, str(self._tmpdir))
def setUp(self): super(HelloWorldBashTest, self).setUp() from cosmo_tester.framework.git_helper import clone self.repo_dir = clone(self.CLOUDIFY_EXAMPLES_URL, self.workdir)
def clone_hello_world(workdir): return clone(CLOUDIFY_HELLO_WORLD_EXAMPLE_URL, workdir)