def parse_output(container_id): d = Docker() raw_logs = d.logs(container_id) run_output = raw_logs.splitlines() # The final 2 lines we care about have some specific strings # search for them and determine if it was actually a successful run # Time taken for tests: 27.048s # Time per container: 535.584ms [mean] | 1252.565ms [90th] | 2002.064ms [99th] # noqa parsed = run_output[-1].replace('Time per container: ', '').split('|') mean = parsed[0].replace('ms [mean] ', '') ninety = parsed[1].replace('ms [90th] ', '') ninetynine = parsed[2].replace('ms [99th] ', '') total_parsed = run_output[-2].replace('Time taken for tests: ', '') total_time = total_parsed.replace('s', '') action_set("results.total-time", {'value': total_time, 'units': 's'}) action_set("results.mean-time", {'value': mean, 'units': 'ms'}) action_set("results.90th-percentile", {'value': ninety, 'units': 'ms'}) action_set("results.99th-percentile", {'value': ninetynine, 'units': 'ms'}) Benchmark.set_composite_score(total_time, 'sec', 'desc')
def run_ems(): # authenticate to private docker repository d = Docker() cfg = config() d.login(cfg['distribution-user'], cfg['distribution-pass'], cfg['distribution-email']) # Render the template render('docker-compose.yml', 'files/ems/docker-compose.yml', cfg) comp = Compose('files/ems') comp.up()
def healthcheck(self): """ Healthcheck is used to poll the Docker health state. A health test command need to be specified in the Compose manifest or in the Dockerfile. If the Docker container is not healthy a :class:`DockerComponentUnhealthy` is raised. If not, the container is currently considered healthy by the test command. :raises DockerComponentUnhealthy: The containers healthcheck failed :raises DockerComponentStarting: The container is starting up """ hookenv.log("Healthchecking {}".format(self.name), level=hookenv.DEBUG) health = Docker().healthcheck(self.name, verbose=True) if not health: raise DockerComponentUnhealthy(self) if health["Status"] == "starting": raise DockerComponentStarting(self) if health["Status"] != "healthy": raise DockerComponentUnhealthy(self)
def dockerhost_connected(dockerhost): """ Transmits the docker url to any subordinates requiring it. :return: None """ dockerhost.configure(Docker().socket)
def publish_config(): endpoint = endpoint_from_flag("endpoint.docker.joined") endpoint.set_config( socket=Docker().socket, runtime="docker", nvidia_enabled=is_state("nvidia-docker.supported"), )
def parse_output(container_id): d = Docker() raw_logs = d.logs(container_id) run_output = raw_logs.splitlines() # The final 2 lines we care about have some specific strings # search for them and determine if it was actually a successful run # Time taken for tests: 27.048s # Time per container: 535.584ms [mean] | 1252.565ms [90th] | 2002.064ms [99th] # noqa parsed = run_output[-1].replace('Time per container: ', '').split('|') mean = parsed[0].replace('ms [mean] ', '') ninety = parsed[1].replace('ms [90th] ', '') ninetynine = parsed[2].replace('ms [99th] ', '') total_parsed = run_output[-2].replace('Time taken for tests: ', '') total_time = total_parsed.replace('s', '') action_set( "results.total-time", {'value': total_time, 'units': 's'} ) action_set( "results.mean-time", {'value': mean, 'units': 'ms'} ) action_set( "results.90th-percentile", {'value': ninety, 'units': 'ms'} ) action_set( "results.99th-percentile", {'value': ninetynine, 'units': 'ms'} ) Benchmark.set_composite_score( total_time, 'sec', 'desc' )
def publish_config(): endpoint = endpoint_from_flag('endpoint.docker.joined') endpoint.set_config(socket=Docker().socket, runtime='docker', nvidia_enabled=is_state('nvidia-docker.supported'))
def dockerhost_connected(dockerhost): '''Transmits the docker url to any subordinates requiring it''' dockerhost.configure(Docker().socket)
def logspout_to_the_rescue(): status_set('maintenance', 'Pulling logspout container image') d = Docker() d.pull(config('container-image')) set_state('logstash.pulled') status_set('waiting', 'Logspout image pulled')
def docker(self): return Docker()
def test_docker_init_workspace(self): devel = Docker(workspace="files/tmp") assert "{}".format(devel.workspace) == "files/tmp"
def test_docker_init_socket(self): docker = Docker(socket="tcp://127.0.0.1:2357") assert docker.socket == "tcp://127.0.0.1:2357"
def bootstrap(self): return Docker(socket="unix:///var/run/docker-bootstrap.sock")