def start(self): """Start the unit agent process.""" self.service_state_manager = ServiceStateManager(self.client) self.executor.start() # Retrieve our unit and configure working directories. service_name = self.unit_name.split("/")[0] service_state = yield self.service_state_manager.get_service_state( service_name) self.unit_state = yield service_state.get_unit_state(self.unit_name) self.unit_directory = os.path.join( self.config["juju_directory"], "units", self.unit_state.unit_name.replace("/", "-")) self.state_directory = os.path.join(self.config["juju_directory"], "state") # Setup the server portion of the cli api exposed to hooks. from twisted.internet import reactor self.api_socket = reactor.listenUNIX( os.path.join(self.unit_directory, HOOK_SOCKET_FILE), self.api_factory) # Setup the unit state's address address = yield get_unit_address(self.client) yield self.unit_state.set_public_address( (yield address.get_public_address())) yield self.unit_state.set_private_address( (yield address.get_private_address())) # Inform the system, we're alive. yield self.unit_state.connect_agent() self.lifecycle = UnitLifecycle(self.client, self.unit_state, service_state, self.unit_directory, self.executor) self.workflow = UnitWorkflowState(self.client, self.unit_state, self.lifecycle, self.state_directory) if self.get_watch_enabled(): yield self.unit_state.watch_resolved(self.cb_watch_resolved) yield self.unit_state.watch_hook_debug(self.cb_watch_hook_debug) yield service_state.watch_config_state( self.cb_watch_config_changed) # Fire initial transitions, only if successful if (yield self.workflow.transition_state("installed")): yield self.workflow.transition_state("started") # Upgrade can only be processed if we're in a running state so # for case of a newly started unit, do it after the unit is started. if self.get_watch_enabled(): yield self.unit_state.watch_upgrade_flag( self.cb_watch_upgrade_flag)
def setUp(self): yield super(UnitWorkflowTest, self).setUp() yield self.setup_default_test_relation() self.lifecycle = UnitLifecycle(self.client, self.states["unit"], self.states["service"], self.unit_directory, self.executor) self.juju_directory = self.makeDir() self.state_directory = self.makeDir( path=os.path.join(self.juju_directory, "state")) self.workflow = UnitWorkflowState(self.client, self.states["unit"], self.lifecycle, self.state_directory)
def setUp(self): yield super(UnitLifecycleTest, self).setUp() yield self.setup_default_test_relation() self.lifecycle = UnitLifecycle(self.client, self.states["unit"], self.states["service"], self.unit_directory, self.executor)