Beispiel #1
0
 def setUp(self):
     self.tc = TaskdConnection()
     self.tc.server = "localhost"
     self.tc.group = "Public"
     self.tc.uuid = str(uuid.uuid4())
     self.tc.username = "******"
     self.tc.client_cert = "taskc/fixture/pki/client.cert.pem"
     self.tc.client_key = "taskc/fixture/pki/client.key.pem"
     self.tc.cacert_file = "taskc/fixture/pki/ca.cert.pem"
Beispiel #2
0
 def test_invoke_connection(self):
     options = dict()
     options['server'] = "localhost"
     options['port'] = 53589
     options['group'] = "Public"
     options['username'] = "******"
     options['client_cert'] = "taskc/fixture/pki/client.cert.pem"
     options['client_key'] = "taskc/fixture/pki/client.key.pem"
     options['cacert_file'] = "taskc/fixture/pki/ca.cert.pem"
     our_tc = TaskdConnection(**options)
Beispiel #3
0
    def setUp(self):
        # logging.basicConfig(level=logging.DEBUG)
        self.docker = docker.from_env()
        self.low_level_api = docker.APIClient(
            base_url='unix://var/run/docker.sock')
        # self.volume_name = "taskc_fixture_pki"
        try:
            self.docker.containers.get("taskc_test").remove(force=True)
        except APIError:
            logging.exception(
                "had problem removing the previous test container, it may not have existed!"
            )
        # volume = self.docker.create_volume(self.volume_name)
        # logging.debug(volume)
        pki_abs_path = os.path.abspath("taskc/fixture/pki")
        self.container = self.docker.containers.create(
            "jrabbit/taskd",
            volumes={
                pki_abs_path: {
                    "bind": "/var/lib/taskd/pki",
                    "mode": "rw"
                }
            },
            name="taskc_test",
            publish_all_ports=True)
        # print(self.container)
        self.container.start()
        time.sleep(1)
        exit_code, o = self.container.exec_run(
            "taskd add user Public test_user")
        self.tc = TaskdConnection()
        self.tc.uuid = o.split(b'\n')[0].split()[-1].decode(
            "utf8")  # this type assumption may be wrong in new docker.py
        logging.debug("Type of uuid: %s", type(self.tc.uuid))

        self.tc.server = "localhost"
        c = self.low_level_api.inspect_container("taskc_test")

        self.tc.port = int(
            c['NetworkSettings']['Ports']['53589/tcp'][0]['HostPort'])
        # self.tc.uuid = os.getenv("TEST_UUID")
        self.tc.group = "Public"
        self.tc.username = "******"
        self.tc.client_cert = "taskc/fixture/pki/client.cert.pem"
        self.tc.client_key = "taskc/fixture/pki/client.key.pem"
        self.tc.cacert_file = "taskc/fixture/pki/ca.cert.pem"
        time.sleep(1)
Beispiel #4
0
    def setUp(self):
        # logging.basicConfig(level=logging.DEBUG)
        self.docker = Client(base_url='unix://var/run/docker.sock')
        # self.volume_name = "taskc_fixture_pki"
        try:
            self.docker.remove_container("taskc_test", force=True)
        except APIError as e:
            logging.error(e)
        # volume = self.docker.create_volume(self.volume_name)
        # logging.debug(volume)
        pki_abs_path = os.path.abspath("taskc/fixture/pki")
        host_config = self.docker.create_host_config(
            binds=['{}:/var/lib/taskd/pki'.format(pki_abs_path)],
            publish_all_ports=True)
        self.container = self.docker.create_container(
            "jrabbit/taskd",
            volumes=["/var/lib/taskd/pki"],
            name="taskc_test",
            host_config=host_config)
        # print(self.container)
        self.docker.start(self.container["Id"])
        time.sleep(1)
        our_exec = self.docker.exec_create(self.container["Id"],
                                           "taskd add user Public test_user")
        self.tc = TaskdConnection()
        o = self.docker.exec_start(our_exec['Id'])
        logging.debug(o)
        #bytes
        our_uuid = o.split(b'\n')[0].split()[-1]
        if six.PY3:
            our_uuid = our_uuid.decode("utf8")
        self.tc.uuid = our_uuid
        logging.debug("Type of uuid: %s", type(self.tc.uuid))

        self.tc.server = "localhost"
        c = self.docker.inspect_container("taskc_test")

        self.tc.port = int(
            c['NetworkSettings']['Ports']['53589/tcp'][0]['HostPort'])
        # self.tc.uuid = os.getenv("TEST_UUID")
        self.tc.group = "Public"
        self.tc.username = "******"
        self.tc.client_cert = "taskc/fixture/pki/client.cert.pem"
        self.tc.client_key = "taskc/fixture/pki/client.key.pem"
        self.tc.cacert_file = "taskc/fixture/pki/ca.cert.pem"
        time.sleep(1)
Beispiel #5
0
def index():
    tc = TaskdConnection()
    tc.client_cert = "pki/client.cert.pem"
    tc.client_key = "pki/client.key.pem"
    tc.cacert_file = "pki/ca.cert.pem"
    with open("conf.json") as j:
        config = json.load(j)
    tc.server = config['server']
    tc.group = config['group']
    tc.username = config['username']
    tc.uuid = config['user_uuid']
    tc.connect()
    resp = tc.stats()
    d = dict([x.split(":") for x in resp.data])
    # do some humanizing of the data
    d.update({
        k: humanize.naturalsize(v)
        for k, v in d.items() if "bytes" in k or k == "user data"
    })
    d['uptime'] = humanize.naturaldelta(
        datetime.timedelta(seconds=int(d['uptime'])))
    # d['total bytes in'] =  humanize.naturalsize(d['total bytes in'])
    tpl = template("stats.tpl", response=d)
    return tpl