class TestConnectionUnit(unittest.TestCase): 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" @mock.patch("taskc.simple.TaskdConnection.recv") @mock.patch("taskc.simple.TaskdConnection.conn", create=True) @mock.patch("taskc.simple.TaskdConnection._mkmsg") @mock.patch("taskc.simple.TaskdConnection._connect") def test_pull(self, tdc_connect, mk_msg, conn, recv): output = "timbo?" recv.return_value = output self.assertEqual(self.tc.pull(), output) tdc_connect.assert_called_with() mk_msg.assert_called_with('sync') @mock.patch("taskc.simple.TaskdConnection.recv") @mock.patch("taskc.simple.TaskdConnection.conn", create=True) # @mock.patch("taskc.transaction.prep_message") @mock.patch("taskc.simple.TaskdConnection._connect") def test_put(self, tdc_connect, conn, recv): tasks = "{This is a task}\n{this is another task}" self.tc.put(tasks) # prep_msg.assert_ tdc_connect.assert_called_with()
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"
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)
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)
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)
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)
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
class TestConnection(unittest.TestCase): 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) def test_connect(self): self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() # from IPython import embed # embed() def test_put(self): assert self.tc.uuid self.tc.put("") tasks = """{"description":"hang up posters","entry":"20141130T081652Z","status":"pending","uuid":"0037aa92-45e5-44a6-8f34-2f92989f173a"} {"description":"make pb ramen","entry":"20141130T081700Z","status":"pending","uuid":"dd9b71db-f51c-4026-9e46-bb099df8dd3f"} {"description":"fold clothes","entry":"20141130T081709Z","status":"pending","uuid":"d0f53865-2f01-42a8-9f9e-3652c63f216d"}""" resp = self.tc.put(tasks) self.assertEqual(resp.status_code, 200) # might not be correct depends on state of taskd if six.PY3: def test_cadata(self): "This doesn't work in python2.7??" self.tc.cacert_file = False with open("taskc/fixture/pki/ca.cert.pem") as ca: self.tc.cacert = ca.read() self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() def tearDown(self): print(self.docker.logs(self.container['Id'], stdout=True, stderr=True)) self.docker.remove_container(self.container['Id'], force=True)
def setUp(self): self.tc = TaskdConnection.from_taskrc("taskc/fixture/.taskrc")
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
class TestConnection(unittest.TestCase): 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) def test_connect(self): self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() # from IPython import embed # embed() def test_put(self): assert self.tc.uuid self.tc.put("") tasks = """{"description":"hang up posters","entry":"20141130T081652Z","status":"pending","uuid":"0037aa92-45e5-44a6-8f34-2f92989f173a"} {"description":"make pb ramen","entry":"20141130T081700Z","status":"pending","uuid":"dd9b71db-f51c-4026-9e46-bb099df8dd3f"} {"description":"fold clothes","entry":"20141130T081709Z","status":"pending","uuid":"d0f53865-2f01-42a8-9f9e-3652c63f216d"}""" resp = self.tc.put(tasks) self.assertEqual(resp.status_code, 200) # might not be correct depends on state of taskd def test_cadata(self): self.tc.cacert_file = False with open("taskc/fixture/pki/ca.cert.pem") as ca: self.tc.cacert = ca.read() self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() def tearDown(self): print(self.container.logs()) self.container.remove(force=True)
class TestConnection(unittest.TestCase): 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) def test_connect(self): self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() # from IPython import embed # embed() def test_put(self): assert self.tc.uuid self.tc.put("") tasks = """{"description":"hang up posters","entry":"20141130T081652Z","status":"pending","uuid":"0037aa92-45e5-44a6-8f34-2f92989f173a"} {"description":"make pb ramen","entry":"20141130T081700Z","status":"pending","uuid":"dd9b71db-f51c-4026-9e46-bb099df8dd3f"} {"description":"fold clothes","entry":"20141130T081709Z","status":"pending","uuid":"d0f53865-2f01-42a8-9f9e-3652c63f216d"}""" resp = self.tc.put(tasks) self.assertEqual(resp.status_code, 200) # might not be correct depends on state of taskd if six.PY3: def test_cadata(self): "This doesn't work in python2.7??" self.tc.cacert_file = False with open("taskc/fixture/pki/ca.cert.pem") as ca: self.tc.cacert = ca.read() self.tc._connect() # print self.tc.conn.getpeername() self.assertEqual(self.tc.conn.getpeername(), ('127.0.0.1', self.tc.port)) # make sure we're on TLS v2 per spec self.assertEqual(self.tc.conn.context.protocol, 2) self.tc.conn.close() def tearDown(self): print(self.docker.logs(self.container['Id'], stdout=True, stderr=True)) self.docker.remove_container(self.container['Id'], force=True)