def _set_policy_with(self, rules, filename='rules.zip'): rules_zip_path = self._make_zip_file_from(filename, rules) zaza_model.attach_resource(self.application_name, 'policyd-override', rules_zip_path) self._set_config(True) zaza_model.block_until_wl_status_info_starts_with( self.application_name, "PO:", negate_match=False)
def test_002_policyd_bad_yaml(self): """Test bad yaml file in the zip file is handled.""" bad = self.bad bad_zip_path = self._make_zip_file_from('bad.zip', bad) logging.info("Attaching bad zip file as a resource") zaza_model.attach_resource(self.application_name, 'policyd-override', bad_zip_path) zaza_model.block_until_all_units_idle() logging.debug("Now setting config to true") self._set_config(True) # ensure that the workload status info line starts with PO (broken): # to show that it didn't work logging.info( "Checking for workload status line starts with PO (broken):") zaza_model.block_until_wl_status_info_starts_with( self.application_name, "PO (broken):") logging.debug("App status is valid for broken yaml file") zaza_model.block_until_all_units_idle() # now verify that no file got landed on the machine if self.path_infix: path = os.path.join( "/etc", self._service_name, "policy.d", self.path_infix, 'file2.yaml') else: path = os.path.join( "/etc", self._service_name, "policy.d", 'file2.yaml') logging.info("Now checking that file {} is not present.".format(path)) zaza_model.block_until_file_missing(self.application_name, path) self._set_config(False) zaza_model.block_until_all_units_idle() logging.info("OK")
def basic_setup(): """Run setup for testing Trilio. Setup for testing Trilio is currently part of functional tests. """ logging.info("Configuring NFS Server") nfs_server_ip = zaza_model.get_app_ips("nfs-server-test-fixture")[0] trilio_wlm_unit = zaza_model.get_first_unit_name("trilio-wlm") nfs_shares_conf = {"nfs-shares": "{}:/srv/testing".format(nfs_server_ip)} _trilio_services = ["trilio-wlm", "trilio-data-mover"] conf_changed = False for juju_service in _trilio_services: app_config = zaza_model.get_application_config(juju_service) if app_config["nfs-shares"] != nfs_shares_conf["nfs-shares"]: zaza_model.set_application_config(juju_service, nfs_shares_conf) conf_changed = True if conf_changed: zaza_model.wait_for_agent_status() # NOTE(jamespage): wlm-api service must be running in order # to execute the setup actions zaza_model.block_until_service_status( unit_name=trilio_wlm_unit, services=["wlm-api"], target_status="active", ) logging.info("Executing create-cloud-admin-trust") password = juju_utils.leader_get("keystone", "admin_passwd") generic_utils.assertActionRanOK( zaza_model.run_action_on_leader( "trilio-wlm", "create-cloud-admin-trust", raise_on_failure=True, action_params={"password": password}, ) ) logging.info("Executing create-license") test_license = os.environ.get("TEST_TRILIO_LICENSE") if test_license and os.path.exists(test_license): zaza_model.attach_resource("trilio-wlm", resource_name='license', resource_path=test_license) generic_utils.assertActionRanOK( zaza_model.run_action_on_leader( "trilio-wlm", "create-license", raise_on_failure=True ) ) else: logging.error("Unable to find Trilio License file")
def test_attach_resource(self): self.patch_object(model, 'get_juju_model', return_value=self.model_name) self.patch_object(model, 'subprocess') _application = "application" _resource_name = "myresource" _resource_path = "/path/to/{}.tar.gz".format(_resource_name) model.attach_resource(_application, _resource_name, _resource_path) self.subprocess.check_call.assert_called_once_with([ "juju", "attach-resource", "-m", self.model_name, _application, "{}={}".format(_resource_name, _resource_path) ])
def test_001_policyd_good_yaml(self): """Test that the policyd with a good zipped yaml file.""" good = self.good good_zip_path = self._make_zip_file_from('good.zip', good) logging.info("Attaching good zip file as a resource.") zaza_model.attach_resource(self.application_name, 'policyd-override', good_zip_path) zaza_model.block_until_all_units_idle() logging.debug("Now setting config to true") self._set_config(True) # check that the file gets to the right location if self.path_infix: path = os.path.join( "/etc", self._service_name, "policy.d", self.path_infix, 'file1.yaml') else: path = os.path.join( "/etc", self._service_name, "policy.d", 'file1.yaml') logging.info("Now checking for file contents: {}".format(path)) zaza_model.block_until_file_has_contents(self.application_name, path, "rule1: '!'") # ensure that the workload status info line starts with PO: logging.info("Checking for workload status line starts with PO:") zaza_model.block_until_wl_status_info_starts_with( self.application_name, "PO:") logging.debug("App status is valid") # disable the policy override logging.info("Disabling policy override by setting config to false") self._set_config(False) # check that the status no longer has "PO:" on it. # we have to do it twice due to async races and that some info lines # erase the PO: bit prior to actuall getting back to idle. The double # check verifies that the charms have started, the idle waits until it # is finished, and then the final check really makes sure they got # switched off. zaza_model.block_until_wl_status_info_starts_with( self.application_name, "PO:", negate_match=True) zaza_model.block_until_all_units_idle() zaza_model.block_until_wl_status_info_starts_with( self.application_name, "PO:", negate_match=True) # verify that the file no longer exists logging.info("Checking that {} has been removed".format(path)) zaza_model.block_until_file_missing(self.application_name, path) logging.info("OK")
def license_setup(): """Run setup Trilio license setup.""" logging.info("Executing create-license") test_license = os.environ.get("TEST_TRILIO_LICENSE") if test_license and os.path.exists(test_license): zaza_model.attach_resource("trilio-wlm", resource_name='license', resource_path=test_license) generic_utils.assertActionRanOK( zaza_model.run_action_on_leader("trilio-wlm", "create-license", raise_on_failure=True)) else: logging.error("Unable to find Trilio License file")
def attach_file_resource(application_name, resource_name, file_content, file_suffix=".txt"): """Attaches a file as a Juju resource given the file content and suffix. The file content will be written into a temporary file with the given suffix, and it will be attached to the Juju application. :param application_name: Juju application name. :type application_name: string :param resource_name: Juju resource name. :type resource_name: string :param file_content: The content of the file that will be attached :type file_content: string :param file_suffix: File suffix. This should be used to set the file extension for applications that are sensitive to this. :type file_suffix: string :returns: None """ with tempfile.NamedTemporaryFile(mode='w', suffix=file_suffix) as fp: fp.write(file_content) fp.flush() model.attach_resource(application_name, resource_name, fp.name)