def __init__(self, charm, relation_name): super().__init__(charm, relation_name) self.fw_adapter = FrameworkAdapter(self.framework) self.relation_name = relation_name self.fw_adapter.observe(charm.on[relation_name].relation_changed, self.on_relation_changed)
def test__am_i_leader__returns_true_if_unit_is_leader(self): # Setup mock_framework = create_autospec(self.create_framework(), spec_set=True) mock_framework.model.unit.is_leader.return_value = True # Exercise adapter = FrameworkAdapter(mock_framework) is_leader = adapter.am_i_leader() # Assert assert is_leader
def test__get_app_name__returns_the_name_of_the_app(self): # Setup mock_framework = create_autospec(self.create_framework(), spec_set=True) mock_app_name = str(uuid4()) mock_framework.model.app.name = mock_app_name # Exercise adapter = FrameworkAdapter(mock_framework) app_name = adapter.get_app_name() # Assert assert app_name == mock_app_name
def test__get_config__returns_a_value_given_a_key(self): # Setup mock_framework = create_autospec(self.create_framework(), spec_set=True) mock_key = str(uuid4()) mock_value = str(uuid4()) mock_framework.model.config = {mock_key: mock_value} # Exercise adapter = FrameworkAdapter(mock_framework) value = adapter.get_config(mock_key) # Assert assert value == mock_value
def __init__(self, *args): super().__init__(*args) self.dbd_requires = HostPortRequires(self, "slurmdbd-host-port") self.fw_adapter = FrameworkAdapter(self.framework) self.slurm_snap = self.slurm_instance_manager_cls(self, "slurmdctld") self.munge = MungeProvides(self, "munge") event_handler_bindings = { self.on.install: self._on_install, self.dbd_requires.on.host_port_available: self._on_dbd_host_port_available, } for event, handler in event_handler_bindings.items(): self.fw_adapter.observe(event, handler)
def __init__(self, charm, key): super().__init__(charm, key) self.snap_mode = key self.fw_adapter = FrameworkAdapter(self.framework) # Set the template and config file paths based on the snap.mode. # Throw an exception if initialized with an unsupported snap.mode. if self.snap_mode == "slurmdbd": self.slurm_config_yaml = self.SLURM_CONFIGURATOR_TEMPLATES_DIR / 'slurmdbd.yaml' self.slurm_config_template = self.TEMPLATE_DIR / 'slurmdbd.yaml.tmpl' elif self.snap_mode in ["slurmd", "slurmrestd", "slurmctld"]: self.slurm_config_yaml = self.SLURM_CONFIGURATOR_TEMPLATES_DIR / 'slurm.yaml' self.slurm_config_template = self.TEMPLATE_DIR / 'slurm.yaml.tmpl' else: self.logger.error( f"Slurm component not supported: {self.snap_mode}", exc_info=True)
def test__get_config__returns_the_config_dict_when_no_key_given(self): # Setup mock_framework = create_autospec(self.create_framework(), spec_set=True) mock_config = { str(uuid4()): str(uuid4()), str(uuid4()): str(uuid4()), str(uuid4()): str(uuid4()), str(uuid4()): str(uuid4()), } mock_framework.model.config = mock_config # Exercise adapter = FrameworkAdapter(mock_framework) config = adapter.get_config() # Assert assert config == mock_config
def test__get_image_meta__returns_an_image_meta_object( self, mock_fetch_image_meta_func): # Setup framework = self.create_framework() mock_framework = create_autospec(framework, spec_set=True) mock_framework.model = create_autospec(framework.model, spec_set=True) image_name = uuid4() # Exercise adapter = FrameworkAdapter(mock_framework) image_meta = adapter.get_image_meta(image_name) # Assert assert mock_fetch_image_meta_func.call_count == 1 assert mock_fetch_image_meta_func.call_args == \ call(image_name, mock_framework.model.resources) assert image_meta == mock_fetch_image_meta_func.return_value
def __init__(self, *args): super().__init__(*args) self._state.set_default(db_info=None) self._state.set_default(munge_key=None) # provides host port to slurmctld self.dbd_provides = HostPortProvides(self, "slurmdbd-host-port", f'{socket.gethostname()}', '6819') self.slurm_snap = self.slurm_instance_manager_cls(self, "slurmdbd") self.fw_adapter = FrameworkAdapter(self.framework) self.db = MySQLClient(self, "db") self.munge = MungeRequires(self, "munge") event_handler_bindings = { self.db.on.database_available: self._on_database_available, self.munge.on.munge_available: self._on_munge_available, self.on.install: self._on_install, self.on.start: self._on_start, } for event, handler in event_handler_bindings.items(): self.fw_adapter.observe(event, handler)
def __init__(self, *args): super().__init__(*args) # Abstract out framework and friends so that this object is not # too tightly coupled with the underlying framework's implementation. # From this point forward, our Charm object will only interact with the # adapter and not directly with the framework. self.fw_adapter = FrameworkAdapter(self.framework) self.prometheus = PrometheusInterface(self, 'http-api') self.alertmanager = AlertManagerInterface(self, 'alertmanager') # Bind event handlers to events event_handler_bindings = { self.on.start: self.on_start, self.on.config_changed: self.on_config_changed, self.on.upgrade_charm: self.on_upgrade, self.on.stop: self.on_stop, self.alertmanager.on.new_relation: self.on_new_alertmanager_relation } for event, handler in event_handler_bindings.items(): self.fw_adapter.observe(event, handler) self._stored.set_default(is_started=False)
def __init__(self, *args): super().__init__(*args) # Abstract out framework and friends so that this object is not # too tightly coupled with the underlying framework's implementation. # From this point forward, our Charm object will only interact with the # adapter and not directly with the framework. self.fw_adapter = FrameworkAdapter(self.framework) self.prom_relation_name = 'prometheus' self.prom_interface = \ PrometheusInterface(self, self.prom_relation_name) # Bind event handlers to events event_handler_bindings = { self.on.start: self.on_start, self.on.config_changed: self.on_config_changed, self.on.upgrade_charm: self.on_upgrade, self.on.stop: self.on_stop, self.prom_interface.on.new_prom_rel: self.on_new_prom_rel } for event, handler in event_handler_bindings.items(): self.fw_adapter.observe(event, handler)