Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions perfkitbenchmarker/benchmark_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,20 @@ def UnPickleLock(locked: bool, *args):
)
# pyformat: disable
# TODO(user): Delete this flag after fulling updating gcl.
flags.DEFINE_enum('benchmark_compatibility_checking', SUPPORTED,
[SUPPORTED, NOT_EXCLUDED, SKIP_CHECK],
'Method used to check compatibility between the benchmark '
' and the cloud. ' + SUPPORTED + ' runs the benchmark only'
' if the cloud provider has declared it supported. ' +
NOT_EXCLUDED + ' runs the benchmark unless it has been'
' declared not supported by the cloud provider. ' + SKIP_CHECK
+ ' does not do the compatibility'
' check.')
flags.DEFINE_enum(
'benchmark_compatibility_checking',
SUPPORTED,
[SUPPORTED, NOT_EXCLUDED, SKIP_CHECK],
'Method used to check compatibility between the benchmark and the cloud. '
+ SUPPORTED
+ ' runs the benchmark only'
' if the cloud provider has declared it supported. '
+ NOT_EXCLUDED
+ ' runs the benchmark unless it has been'
' declared not supported by the cloud provider. '
+ SKIP_CHECK
+ ' does not do the compatibility check.',
)
# pyformat: enable


Expand Down Expand Up @@ -282,8 +287,7 @@ def vm_groups(self) -> dict[str, list[virtual_machine.BaseVirtualMachine]]:
"""Returns the vm groups in the benchmark."""
vm_groups = dict(self.unmanaged_vm_groups)
vm_groups.update({
name: list(group.vms)
for name, group in self.managed_vm_groups.items()
name: list(group.vms) for name, group in self.managed_vm_groups.items()
})
return vm_groups

Expand Down Expand Up @@ -877,7 +881,9 @@ def ConstructCapacityReservations(self):
providers.LoadProvider(cloud)
capacity_reservation_class = capacity_reservation.GetResourceClass(cloud)
self.capacity_reservations.append(
capacity_reservation_class(vm_group) # pytype: disable=not-instantiable
capacity_reservation_class(
vm_group
) # pytype: disable=not-instantiable
)

def _CheckBenchmarkSupport(self, cloud):
Expand Down Expand Up @@ -939,9 +945,9 @@ def ConstructVirtualMachines(self):

jujuvm.units.extend(vms) # pytype: disable=attribute-error
if jujuvm and jujuvm not in self.vms:
self.unmanaged_vm_groups[
'%s_juju_controller' % group_spec.cloud
] = [jujuvm]
self.unmanaged_vm_groups['%s_juju_controller' % group_spec.cloud] = [
jujuvm
]

self.unmanaged_vm_groups[group_name] = vms

Expand Down Expand Up @@ -1247,7 +1253,7 @@ def Delete(self):
if self.managed_vm_groups:
background_tasks.RunThreaded(
lambda vm_group: vm_group.Delete(),
list(self.managed_vm_groups.values())
list(self.managed_vm_groups.values()),
)

if self.vms:
Expand Down Expand Up @@ -1338,9 +1344,9 @@ def _GetResourceDict(self, time_format, timeout_minutes=None):
tags = {
resource_type.TIMEOUT_METADATA_KEY: timeout_utc.strftime(time_format),
'create_time_utc': now_utc.strftime(time_format),
'benchmark': self.name,
'benchmark': self._SafeLabelKeyOrValue(self.name),
'perfkit_uuid': self.uuid,
'owner': FLAGS.owner,
'owner': self._SafeLabelKeyOrValue(FLAGS.owner),
'benchmark_uid': self.uid,
}

Expand Down
10 changes: 10 additions & 0 deletions tests/benchmark_spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from absl.testing import flagsaver
import mock
from perfkitbenchmarker import benchmark_spec
from perfkitbenchmarker import flags as pkb_flags
from perfkitbenchmarker import context
from perfkitbenchmarker import flag_alias
from perfkitbenchmarker import pkb # pylint: disable=unused-import # noqa
Expand Down Expand Up @@ -125,6 +126,15 @@ def setUp(self):
self.addCleanup(context.SetThreadBenchmarkSpec, None)


class GetResourceTagsTestCase(_BenchmarkSpecTestCase):

@mock.patch('getpass.getuser', return_value='Name_Surname')
def testOwnerFromGetuserIsSanitized(self, _):
FLAGS.owner = pkb_flags.GetCurrentUser()
spec = pkb_common_test_case.CreateBenchmarkSpecFromYaml(SIMPLE_CONFIG)
self.assertEqual('name_surname', spec.GetResourceTags()['owner'])


class GenericTestCase(_BenchmarkSpecTestCase):

def testGetSamples(self):
Expand Down