def test_short_id(): mock() b = DockerBackend() operation = b.get_images() images_response = operation.response assert images_response[0].short_id == image_data[0]["Id"][:12] assert images_response[1].short_id == "3ab9a7ed8a16"
def test_short_id(): mock() b = DockerBackend() operation = b.get_images() images_response = operation.response assert images_response[0].short_id == image_data[0]["Id"][ image_data[0]["Id"].index(":") + 1:][:12]
def test_stats(): mock() b = DockerBackend() c = b.get_containers() c0 = c.response.pop() operation = c0.stats() stats_stream = operation.response assert next(stats_stream)
def test_images_call(): mock() b = DockerBackend() operation = b.get_images() images_response = operation.response assert len(images_response) == 1 assert images_response[0].image_id == image_data["Id"] assert images_response[0].short_name == image_data["RepoTags"][0]
def __init__(self): self.d = DockerBackend() self.loop, self.ui = get_app_in_loop(PALLETE) self.ui.commander = Commander(self.ui, self.d) self.rt_thread = threading.Thread(target=self.realtime_updates, daemon=True) self.rt_thread.start()
def test_images_call(): mock() b = DockerBackend() operation = b.get_images(cached=False) images_response = operation.response assert len(images_response) == 1 assert images_response[0].image_id == image_data[0]["Id"] assert images_response[0].short_name == image_data[0]["RepoTags"][0] assert images_response[0].parent_id == image_data[0]["ParentId"] assert images_response[0].created_int == image_data[0]["Created"] assert [str(x) for x in images_response[0].names] == image_data[0]["RepoTags"]
def test_containers_call(): mock() b = DockerBackend() operation = b.get_containers(cached=False) containers_response = operation.response assert len(containers_response) == 1 assert containers_response[0].container_id == container_data["Id"] assert containers_response[0].names == container_data["Names"] assert containers_response[0].short_name == container_data["Names"][0] assert containers_response[0].created_int == container_data["Created"] assert containers_response[0].command == container_data["Command"] assert containers_response[0].nice_status == container_data["Status"] assert containers_response[0].image_id == container_data["ImageID"]
class Application: def __init__(self): self.d = DockerBackend() self.loop, self.ui = get_app_in_loop(PALLETE) self.ui.commander = Commander(self.ui, self.d) self.rt_thread = threading.Thread(target=self.realtime_updates, daemon=True) self.rt_thread.start() def run(self): self.ui.run_command(DisplayListingCommand.name, queue=SameThreadPriority()) self.loop.run() def realtime_updates(self): """ fetch realtime events from docker and pass them to buffers :return: None """ # TODO: make this available for every buffer logger.info("starting receiving events from docker") it = self.d.realtime_updates() while True: try: event = next(it) except NotifyError as ex: self.ui.notify_message("error when receiving realtime events from docker: %s" % ex, level="error") return for buffer in self.ui.buffers: logger.debug("pass event to buffer %s", buffer) buffer.process_realtime_event(event)
class Application: def __init__(self): self.d = DockerBackend() self.loop, self.ui = get_app_in_loop(PALLETE) self.ui.commander = Commander(self.ui, self.d) self.rt_thread = threading.Thread(target=self.realtime_updates, daemon=True) self.rt_thread.start() def run(self): self.ui.run_command(DisplayListingCommand.name, queue=SameThreadPriority()) self.loop.run() def realtime_updates(self): """ fetch realtime events from docker and pass them to buffers :return: None """ # TODO: make this available for every buffer logger.info("starting receiving events from docker") it = self.d.realtime_updates() while True: try: event = next(it) except NotifyError as ex: self.ui.notify_message("error when receiving realtime events from docker: %s" % ex, level="error") return # we could pass to all buffers, but the buffers can't be rendered since they are not displayed # and hence traceback like this: ListBoxError("Listbox contents too short! ... logger.debug("pass event to current buffer %s", self.ui.current_buffer) self.ui.current_buffer.process_realtime_event(event)
def test_stats(): mock() b = DockerBackend() c = b.get_containers() c0 = c.response.pop() operation = c0.stats() stats_stream = operation.response assert next(stats_stream) for x in c0.d.stats('x', decode=True, stream=True): calculate_cpu_percent(x) t = 0.0 s = 0.0 for x in c0.d.stats('x', decode=True, stream=True): calculate_cpu_percent(x) _, s, t = calculate_cpu_percent2(x, t, s)
def test_short_id(): mock() b = DockerBackend() operation = DockerContainer({"Status": "Up", "Id": "voodoo"}, b).top() top_response = operation.response pt = ProcessList(top_response) # 24502 # \ 24542 # \ 23743 # \ 18725 # \ 18733 # \ 18743 # \ 23819 root_process = pt.get_root_process() assert root_process.pid == "24502" assert pt.get_parent_process(root_process) is None p_24542 = pt.get_first_child_process(root_process) assert p_24542.pid == "24542" assert pt.get_last_child_process(root_process).pid == "24542" p_23743 = pt.get_first_child_process(p_24542) assert p_23743.pid == "23743" assert pt.get_last_child_process(p_24542).pid == "23743" p_18725 = pt.get_first_child_process(p_23743) assert p_18725.pid == "18725" assert pt.get_prev_sibling(p_18725) is None assert pt.get_parent_process(p_18725).pid == "23743" p_18733 = pt.get_next_sibling(p_18725) assert p_18733.pid == "18733" p_23819 = pt.get_last_child_process(p_23743) assert p_23819.pid == "23819" assert pt.get_next_sibling(p_23819) is None assert pt.get_parent_process(p_23819).pid == "23743" p_18743 = pt.get_prev_sibling(p_23819) assert p_18743.pid == "18743" assert pt.get_prev_sibling(p_18733) is p_18725 assert pt.get_next_sibling(p_18733) is p_18743 assert pt.get_prev_sibling(p_18743) is p_18733 assert pt.get_next_sibling(p_18743) is p_23819
class Application: def __init__(self, yolo=False): self.d = DockerBackend() self.loop, self.ui = get_app_in_loop(PALLETE) self.ui.yolo = yolo self.ui.commander = Commander(self.ui, self.d) self.rt_thread = threading.Thread(target=self.realtime_updates, daemon=True) self.rt_thread.start() def run(self): self.ui.run_command(DisplayListingCommand.name, queue=SameThreadPriority()) self.loop.run() def realtime_updates(self): """ fetch realtime events from docker and pass them to buffers :return: None """ # TODO: make this available for every buffer logger.info("starting receiving events from docker") it = self.d.realtime_updates() while True: try: event = next(it) except NotifyError as ex: self.ui.notify_message( "error when receiving realtime events from docker: %s" % ex, level="error") return # FIXME: we should pass events to all buffers # ATM the buffers can't be rendered since they are not displayed # and hence traceback like this: ListBoxError("Listbox contents too short! ... logger.debug("pass event to current buffer %s", self.ui.current_buffer) try: self.ui.current_buffer.process_realtime_event(event) except Exception as ex: # swallow any exc logger.error("error while processing runtime event: %r", ex)
def __init__(self): self.d = DockerBackend() # root widget self.mainframe = urwid.Frame(urwid.SolidFill()) self.buffers = [] self.footer = Footer(self) self.executor = ThreadPoolExecutor(max_workers=4) root_widget = urwid.AttrMap(self.mainframe, "root") self.main_list_buffer = None # singleton screen = urwid.raw_display.Screen() screen.set_terminal_properties(256) screen.register_palette(PALLETE) super().__init__(root_widget, screen=screen) self.handle_mouse = False self.current_buffer = None
def test_short_id(): mock() b = DockerBackend() operation = b.get_images() images_response = operation.response assert images_response[0].short_id == image_data[0]["Id"][image_data[0]["Id"].index(":")+1:][:12]