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 archive_policy_name: Archive policy name
"""
archive_policy_rule = {"name": name}
archive_policy_rule["metric_pattern"] = metric_pattern
archive_policy_rule["archive_policy_name"] = archive_policy_name
archive_policy_rule = {"name": name,
"metric_pattern": metric_pattern,
"archive_policy_name": archive_policy_name}
return self._clients.gnocchi().archive_policy_rule.create(
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 owner: Filter in images for tenant ID
"""
filters = {}
filters["status"] = status
filters = {"status": status}
if visibility:
filters["visibility"] = visibility
if owner:

View File

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

View File

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

View File

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