Skip to content

Commit 66dd10d

Browse files
author
Brian Flores
committed
fix observations
1 parent 7c7223c commit 66dd10d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

SoftLayer/CLI/user/grant_access.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
"""User grant access to devices."""
1+
"""Grants a user access to a given device"""
22
# :license: MIT, see LICENSE for more details.
33

44
import click
55
import SoftLayer
66

77
from SoftLayer.CLI.command import SLCommand as SLCommand
88
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import exceptions
910

1011

1112
@click.command(cls=SLCommand, )
@@ -15,7 +16,7 @@
1516
@click.option('--dedicated', help="dedicated host ID")
1617
@environment.pass_env
1718
def cli(env, identifier, hardware, virtual, dedicated):
18-
"""Grant access from a user to an specific device.
19+
"""Grants a user access to a given device.
1920
2021
Example: slcli user grant-access 123456 --hardware 123456789
2122
"""
@@ -25,20 +26,20 @@ def cli(env, identifier, hardware, virtual, dedicated):
2526
if hardware:
2627
result = mgr.grant_hardware_access(identifier, hardware)
2728
if result:
28-
click.secho("Grant to access to hardware: %s" % hardware, fg='green')
29+
click.secho(f"User {identifier} has been given access to hardware {hardware}", fg='green')
2930

3031
if virtual:
3132
result = mgr.grant_virtual_access(identifier, virtual)
3233
if result:
33-
click.secho("Grant to access to virtual guest: %s" % virtual, fg='green')
34+
click.secho(f"User {identifier} has been given access to hardware {virtual}", fg='green')
3435

3536
if dedicated:
3637
result = mgr.grant_dedicated_access(identifier, dedicated)
3738
if result:
38-
click.secho("Grant to access to dedicated host: %s" % dedicated, fg='green')
39+
click.secho(f"User {identifier} has been given access to hardware {dedicated}", fg='green')
3940

4041
if not result:
41-
raise SoftLayer.exceptions.SoftLayerError('You need argument a hardware, virtual or dedicated identifier.\n'
42-
'E.g slcli user grant-access 123456 --hardware 91803794\n'
43-
' slcli user grant-access 123456 --dedicated 91803793\n'
44-
' slcli user grant-access 123456 --virtual 91803792')
42+
raise exceptions.CLIAbort('A device option is required.\n'
43+
'E.g slcli user grant-access 123456 --hardware 91803794\n'
44+
' slcli user grant-access 123456 --dedicated 91803793\n'
45+
' slcli user grant-access 123456 --virtual 91803792')

tests/CLI/modules/user_tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ def test_grant_access_dedicated(self):
357357
result = self.run_command(['user', 'grant-access', '123456', '--dedicated', '369852'])
358358
self.assert_no_fail(result)
359359

360+
def test_grant_without_device(self):
361+
result = self.run_command(['user', 'grant-access', '123456'])
362+
self.assertEqual(2, result.exit_code)
363+
self.assertIn('A device option is required.', result.exception.message)
364+
360365
def test_remove_access_hardware(self):
361366
result = self.run_command(['user', 'remove-access', '123456', '--hardware', '147258'])
362367
self.assert_no_fail(result)

0 commit comments

Comments
 (0)