Skip to content

Commit

Permalink
Address PR suggested improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
apozsuse committed Sep 11, 2023
1 parent 96619c1 commit d9a2c5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 2 additions & 4 deletions img_proof/ipa_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ def _launch_instance(self):
if self.additional_info:
kwargs['AdditionalInfo'] = self.additional_info

cpu_options = self.custom_args.get('cpu_options', [])
cpu_options = self.custom_args.get('cpu_options', {})
if cpu_options:
kwargs['CpuOptions'] = {}
for cpu_op in cpu_options:
kwargs['CpuOption'][cpu_op.get('key')] = cpu_op.get('value')
kwargs['CpuOptions'] = cpu_options

try:
instances = resource.create_instances(**kwargs)
Expand Down
15 changes: 6 additions & 9 deletions img_proof/scripts/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,16 @@ def archive_history_item(item, destination, no_color):


def cli_process_cpu_options(cxt, param, value):
cpu_options = []
cpu_options = {}
if value:
try:
for cpu_option in value.split(','):
key, val = cpu_option.split('=', 1)
option = {
'key': key,
'value': val
}
cpu_options.append(option)
cpu_options.update(
dict(option.split('=', 1) for option in value.split(","))
)
except Exception as e:
raise click.BadParameter(
"Issue with cpu-option parameter: %s" % e
"--cpu-options parameter is invalid: %s" % e +
'. (example value: "--cpu-options AmdSevSnp=enabled")'
)
return cpu_options

Expand Down
14 changes: 10 additions & 4 deletions tests/test_ipa_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ def test_cli_process_cpu_options():
{
'input': 'AmdSevSnp=enabled',
'expected_output': {
'key': 'AmdSevSnp',
'value': 'enabled'
'AmdSevSnp': 'enabled'
}
},
{
'input': 'ExceptionShouldBeRaised'
}
},
{
'input': 'AmdSevSnp=enabled,secondOption=secondValue',
'expected_output': {
'AmdSevSnp': 'enabled',
'secondOption': 'secondValue'
}
},
]

for data in TEST_DATA:
Expand All @@ -80,7 +86,7 @@ def test_cli_process_cpu_options():
data['input']
)

assert data['expected_output'] == output[0]
assert data['expected_output'] == output
else:
with pytest.raises(BadParameter) as exc:
cli_utils.cli_process_cpu_options(
Expand Down

0 comments on commit d9a2c5b

Please sign in to comment.