def __init__(self, *args): super().__init__(*args) self._framework_wrapper = FrameworkWrapper(self.framework, self._state) self._resources = { 'mongodb-image': OCIImageResource('mongodb-image') } self._mongo_builder = MongoBuilder( self._framework_wrapper.app_name, self._framework_wrapper.config, self._resources, self._framework_wrapper.goal_state_units ) if self._framework_wrapper.config['enable-sidecar']: self._resources['mongodb-sidecar-image'] = OCIImageResource( 'mongodb-sidecar-image') self._pod = K8sPod(self._framework_wrapper.app_name) self._pvc = K8sPvc(self._framework_wrapper.app_name) self._mongodb = MongoDbServer(self, "mongo") self._k8s_builder = K8sBuilder(self._pvc) delegators = [ (self.on.start, self.on_config_changed_delegator), (self.on.upgrade_charm, self.on_config_changed_delegator), (self.on.config_changed, self.on_config_changed_delegator), (self.on.update_status, self.on_update_status_delegator), (self._mongodb.on.new_client, self.on_new_client_delegator), (self.on.remove_pvc_action, self.on_remove_pvc_action_delegator), ] for delegator in delegators: self.framework.observe(delegator[0], delegator[1])
def __init__(self, framework, key): super().__init__(framework, key) self.framework.observe(self.on.start, self) self.framework.observe(self.on.stop, self) self.framework.observe(self.on.update_status, self) self.framework.observe(self.on.upgrade_charm, self) self.framework.observe(self.on.config_changed, self) self.framework.observe(self.on.cluster_relation_changed, self) self.framework.observe(self.on.cluster_relation_joined, self) self.framework.observe(self.on.kafka_relation_changed, self.expose_relation_data) self._unit = 1 self._zookeeperuri = "" self._pod = K8sPod(self.framework.model.app.name) listen_on_all_addresses = self.model.config['listen-on-all-addresses'] self.cluster = KafkaCluster(self, 'cluster', listen_on_all_addresses) self.client = KafkaClient(self, 'kafka', listen_on_all_addresses, self.model.config['client-port']) self.state.set_default(isStarted=False) self.zookeeper = ZookeeperClient(self, 'zookeeper') self.framework.observe(self.zookeeper.on.zookeeper_ready, self) self.framework.observe(self.zookeeper.on.zookeeper_available, self)
def test_pod_is_ready(self, mock_k8s_api_cls, mock_os): # Setup app_name = f'{uuid4()}' mock_model_name = f'{uuid4()}' mock_unit_name = f'{uuid4()}' mock_os.environ = { 'JUJU_MODEL_NAME': mock_model_name, 'JUJU_UNIT_NAME': mock_unit_name, } mock_k8s_api = mock_k8s_api_cls.return_value mock_k8s_api.get.return_value = { 'kind': 'PodList', 'items': [{ 'metadata': { 'annotations': { 'juju.io/unit': mock_unit_name } }, 'status': { 'phase': 'Running', 'conditions': [{ 'type': 'ContainersReady', 'status': 'True' }] } }], } # Exercise pod = K8sPod(app_name) pod.fetch() # Assert assert mock_k8s_api.get.call_count == 1 assert mock_k8s_api.get.call_args == call( '/api/v1/namespaces/{}/pods?labelSelector=juju-app={}'.format( mock_model_name, app_name)) assert pod.is_running assert pod.is_ready
def test_pod_undefined(self, mock_k8s_api_cls, mock_os): # Setup app_name = f'{uuid4()}' mock_model_name = f'{uuid4()}' mock_unit_name = f'{uuid4()}' mock_os.environ = { 'JUJU_MODEL_NAME': mock_model_name, 'JUJU_UNIT_NAME': mock_unit_name, } mock_k8s_api = mock_k8s_api_cls.return_value mock_k8s_api.get.return_value = {'kind': 'Undefined'} # Exercise pod = K8sPod(app_name) pod.fetch() # Assert assert mock_k8s_api.get.call_count == 1 assert mock_k8s_api.get.call_args == call( '/api/v1/namespaces/{}/pods?labelSelector=juju-app={}'.format( mock_model_name, app_name)) assert not pod.is_running assert not pod.is_ready
def __init__(self, framework, key): super().__init__(framework, key) self.framework.observe(self.on.start, self) # self.framework.observe(self.on.stop, self) self.framework.observe(self.on.update_status, self) self.framework.observe(self.on.upgrade_charm, self) self.framework.observe(self.on.config_changed, self) self.framework.observe(self.on.cluster_relation_changed, self.on_cluster_modified) self.framework.observe(self.on.zookeeper_relation_joined, self.expose_relation_data) self._unit = 1 self._zookeeperuri = "" self._pod = K8sPod(self.framework.model.app.name) self.cluster = ZookeeperCluster(self, 'cluster') self.client = ZookeeperClient(self, 'zookeeper', self.model.config['client-port']) self.state.set_default(isStarted=False) self.framework.observe(self.on.leader_elected, self)