def trends(self, api, *args, **kwargs): """Generate workloads trends HTML report.""" tasks = kwargs.get("tasks", []) or list(args) if not tasks: print("ERROR: At least one task must be specified", file=sys.stderr) return 1 results = [] for task_id in tasks: if os.path.exists(os.path.expanduser(task_id)): results.extend(self._load_task_results_file(api, task_id)) elif strutils.is_uuid_like(task_id): results.append(api.task.get(task_id=task_id, detailed=True)) else: print("ERROR: Invalid UUID or file name passed: %s" % task_id, file=sys.stderr) return 1 result = plot.trends(results) out = kwargs.get("out") if out: output_file = os.path.expanduser(out) with open(output_file, "w+") as f: f.write(result) if kwargs.get("open_it"): webbrowser.open_new_tab("file://" + os.path.realpath(out)) else: print(result)
def test_is_uuid_like(self): self.assertTrue(strutils.is_uuid_like(str(uuid.uuid4()))) self.assertTrue(strutils.is_uuid_like( "{12345678-1234-5678-1234-567812345678}")) self.assertTrue(strutils.is_uuid_like( "12345678123456781234567812345678")) self.assertTrue(strutils.is_uuid_like( "urn:uuid:12345678-1234-5678-1234-567812345678")) self.assertTrue(strutils.is_uuid_like( "urn:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb")) self.assertTrue(strutils.is_uuid_like( "uuid:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb")) self.assertTrue(strutils.is_uuid_like( "{}---bbb---aaa--aaa--aaa-----aaa---aaa--bbb-bbb---bbb-bbb-bb-{}"))
def test_is_uuid_like(self): self.assertTrue(strutils.is_uuid_like(str(uuid.uuid4()))) self.assertTrue( strutils.is_uuid_like("{12345678-1234-5678-1234-567812345678}")) self.assertTrue( strutils.is_uuid_like("12345678123456781234567812345678")) self.assertTrue( strutils.is_uuid_like( "urn:uuid:12345678-1234-5678-1234-567812345678")) self.assertTrue( strutils.is_uuid_like("urn:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb")) self.assertTrue( strutils.is_uuid_like("uuid:bbbaaaaa-aaaa-aaaa-aabb-bbbbbbbbbbbb")) self.assertTrue( strutils.is_uuid_like( "{}---bbb---aaa--aaa--aaa-----aaa---aaa--bbb-bbb---bbb-bbb-bb-{}" ))
def _setup_neutron_floating_ip_pool(self, name_or_id): if name_or_id: if strutils.is_uuid_like(name_or_id): # Looks like an id is provided Return as is. return name_or_id else: # It's a name. Changing to id. for net in self.clients("neutron").list_networks()["networks"]: if net["name"] == name_or_id: return net["id"] # If the name is not found in the list. Exit with error. raise exceptions.ContextSetupFailure( ctx_name=self.get_name(), msg="Could not resolve Floating IP Pool name %s to id" % name_or_id) else: # Pool is not provided. Using the one set as GW for current router. net = self.context["tenant"]["networks"][0] router_id = net["router_id"] router = self.clients("neutron").show_router(router_id)["router"] net_id = router["external_gateway_info"]["network_id"] return net_id
def test_name_is_uuid_like(self): self.assertFalse(strutils.is_uuid_like("asdasdasd"))
def test_id_is_uuid_like(self): self.assertFalse(strutils.is_uuid_like(1234567))
def test_is_uuid_like_insensitive(self): self.assertTrue(strutils.is_uuid_like(str(uuid.uuid4()).upper()))