Merge "refectoring: Eliminate repetitive code"

This commit is contained in:
Zuul 2024-03-27 21:40:53 +00:00 committed by Gerrit Code Review
commit c5cb9ba25b
5 changed files with 18 additions and 20 deletions

View File

@ -58,9 +58,9 @@ class GnocchiService(service.Service):
:param metric_pattern: Wildcard of metric name to match :param metric_pattern: Wildcard of metric name to match
:param archive_policy_name: Archive policy name :param archive_policy_name: Archive policy name
""" """
archive_policy_rule = {"name": name} archive_policy_rule = {"name": name,
archive_policy_rule["metric_pattern"] = metric_pattern "metric_pattern": metric_pattern,
archive_policy_rule["archive_policy_name"] = archive_policy_name "archive_policy_name": archive_policy_name}
return self._clients.gnocchi().archive_policy_rule.create( return self._clients.gnocchi().archive_policy_rule.create(
archive_policy_rule) archive_policy_rule)

View File

@ -132,8 +132,7 @@ class GlanceV2Service(service.Service, glance_common.GlanceMixin):
:param visibility: Filter in images for the specified visibility :param visibility: Filter in images for the specified visibility
:param owner: Filter in images for tenant ID :param owner: Filter in images for tenant ID
""" """
filters = {} filters = {"status": status}
filters["status"] = status
if visibility: if visibility:
filters["visibility"] = visibility filters["visibility"] = visibility
if owner: if owner:

View File

@ -127,9 +127,8 @@ class SenlinScenario(scenario.OpenStackScenario):
:returns: object of profile created :returns: object of profile created
""" """
attrs = {} attrs = {"spec": spec,
attrs["spec"] = spec "name": self.generate_random_name()}
attrs["name"] = self.generate_random_name()
if metadata: if metadata:
attrs["metadata"] = metadata attrs["metadata"] = metadata

View File

@ -34,9 +34,9 @@ class GnocchiServiceTestCase(test.TestCase):
definition = [{"granularity": "0:00:01", "timespan": "1:00:00"}] definition = [{"granularity": "0:00:01", "timespan": "1:00:00"}]
aggregation_methods = [ aggregation_methods = [
"std", "count", "95pct", "min", "max", "sum", "median", "mean"] "std", "count", "95pct", "min", "max", "sum", "median", "mean"]
archive_policy = {"name": "fake_name"} archive_policy = {"name": "fake_name",
archive_policy["definition"] = definition "definition": definition,
archive_policy["aggregation_methods"] = aggregation_methods "aggregation_methods": aggregation_methods}
self.assertEqual( self.assertEqual(
self.service.create_archive_policy( self.service.create_archive_policy(
@ -65,9 +65,9 @@ class GnocchiServiceTestCase(test.TestCase):
"gnocchi.list_archive_policy") "gnocchi.list_archive_policy")
def test__create_archive_policy_rule(self): def test__create_archive_policy_rule(self):
archive_policy_rule = {"name": "fake_name"} archive_policy_rule = {"name": "fake_name",
archive_policy_rule["metric_pattern"] = "cpu_*" "metric_pattern": "cpu_*",
archive_policy_rule["archive_policy_name"] = "low" "archive_policy_name": "low"}
self.assertEqual( self.assertEqual(
self.service.create_archive_policy_rule( self.service.create_archive_policy_rule(
@ -129,10 +129,10 @@ class GnocchiServiceTestCase(test.TestCase):
"gnocchi.get_measures") "gnocchi.get_measures")
def test__create_metric(self): def test__create_metric(self):
param = {"name": "fake_name"} param = {"name": "fake_name",
param["archive_policy_name"] = "fake_archive_policy" "archive_policy_name": "fake_archive_policy",
param["unit"] = "fake_unit" "unit": "fake_unit",
param["resource_id"] = "fake_resource_id" "resource_id": "fake_resource_id"}
self.assertEqual( self.assertEqual(
self.service.create_metric( self.service.create_metric(
name="fake_name", name="fake_name",

View File

@ -551,8 +551,8 @@ class ManilaSharesTestCase(test.ScenarioTestCase):
def test_set_and_delete_metadata(self, params, iteration, share_number): def test_set_and_delete_metadata(self, params, iteration, share_number):
scenario = shares.SetAndDeleteMetadata() scenario = shares.SetAndDeleteMetadata()
share_list = [{"id": "fake_share_%s_id" % d} for d in range(3)] share_list = [{"id": "fake_share_%s_id" % d} for d in range(3)]
scenario.context = {"tenant": {"shares": share_list}} scenario.context = {"tenant": {"shares": share_list},
scenario.context["iteration"] = iteration "iteration": iteration}
scenario._set_metadata = mock.MagicMock() scenario._set_metadata = mock.MagicMock()
scenario._delete_metadata = mock.MagicMock() scenario._delete_metadata = mock.MagicMock()
expected_set_params = { expected_set_params = {