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 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 test_deferred_restarts(self): """Run deferred restart tests.""" app_config = model.get_application_config(self.application_name) auto_restart_config_key = 'enable-auto-restarts' if auto_restart_config_key not in app_config: raise unittest.SkipTest("Deferred restarts not implemented") # Ensure auto restarts are off. policy_file = '/etc/policy-rc.d/charm-{}.policy'.format( self.application_name) if app_config[auto_restart_config_key]['value']: logging.info("Turning off auto restarts") model.set_application_config( self.application_name, {auto_restart_config_key: 'False'}) logging.info("Waiting for {} to appear on units of {}".format( policy_file, self.application_name)) model.block_until_file_has_contents( self.application_name, policy_file, 'policy_requestor_name') # The block_until_file_has_contents ensures the change we waiting # for has happened, now just wait for any hooks to finish. logging.info("Waiting for units to be idle") model.block_until_all_units_idle() else: logging.info("Auto restarts already disabled") self.run_tests() # Finished so turn auto-restarts back on. logging.info("Turning on auto restarts") model.set_application_config( self.application_name, {auto_restart_config_key: 'True'}) model.block_until_file_missing( self.application_name, policy_file) model.block_until_all_units_idle() self.check_clear_hooks()