Repository: softlayer/softlayer-python
Pull request #1176 (2019-10-04 16:26:16)

Autoscale detail tests


Patch:
diff --git a/SoftLayer/CLI/autoscale/detail.py b/SoftLayer/CLI/autoscale/detail.py
index 88fec1c1..d7484184 100644
--- a/SoftLayer/CLI/autoscale/detail.py
+++ b/SoftLayer/CLI/autoscale/detail.py
@@ -34,7 +34,7 @@ def cli(env, identifier):
     table.add_row(['Cooldown', "{} seconds".format(group.get('cooldown'))])
     table.add_row(['Last Action', utils.clean_time(group.get('lastActionDate'))])
 
-    for network in group.get('networkVlans'):
+    for network in group.get('networkVlans', []):
         network_type = utils.lookup(network, 'networkVlan', 'networkSpace')
         router = utils.lookup(network, 'networkVlan', 'primaryRouter', 'hostname')
         vlan_number = utils.lookup(network, 'networkVlan', 'vlanNumber')
@@ -55,17 +55,16 @@ def cli(env, identifier):
     config_table.add_row(['Core', template.get('startCpus')])
     config_table.add_row(['Ram', template.get('maxMemory')])
     network = template.get('networkComponents')
-    config_table.add_row(['Network', network[0]['maxSpeed']])
+    config_table.add_row(['Network', network[0]['maxSpeed'] if network else 'Default'])
     ssh_keys = template.get('sshKeys', [])
     ssh_manager = SoftLayer.SshKeyManager(env.client)
     for key in ssh_keys:
         # Label isn't included when retrieved from the AutoScale group...
         ssh_key = ssh_manager.get_key(key.get('id'))
         config_table.add_row(['SSH Key {}'.format(ssh_key.get('id')), ssh_key.get('label')])
-    disks = template.get('blockDevices')
-    disk_type = "SAN"
-    if template.get('localDiskFlag'):
-        disk_type = "Local"
+    disks = template.get('blockDevices', [])
+    disk_type = "Local" if template.get('localDiskFlag') else "SAN"
+
     for disk in disks:
         disk_image = disk.get('diskImage')
         config_table.add_row(['{} Disk {}'.format(disk_type, disk.get('device')), disk_image.get('capacity')])
@@ -76,7 +75,7 @@ def cli(env, identifier):
 
     # Policy Config Table
     policy_table = formatting.KeyValueTable(["Policy", "Cooldown"])
-    policies = group.get('policies')
+    policies = group.get('policies', [])
     for policy in policies:
         policy_table.add_row([policy.get('name'), policy.get('cooldown') or group.get('cooldown')])
 
@@ -84,7 +83,7 @@ def cli(env, identifier):
 
     # Active Guests
     member_table = formatting.Table(['Id', 'Hostname', 'Created'], title="Active Guests")
-    guests = group.get('virtualGuestMembers')
+    guests = group.get('virtualGuestMembers', [])
     for guest in guests:
         real_guest = guest.get('virtualGuest')
         member_table.add_row([
diff --git a/SoftLayer/fixtures/SoftLayer_Scale_Group.py b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
index 403bd520..b2361784 100644
--- a/SoftLayer/fixtures/SoftLayer_Scale_Group.py
+++ b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
@@ -1,44 +1,201 @@
 getObject = {
-    "accountId": 31111,
-    "cooldown": 1800,
-    "createDate": "2016-10-25T01:48:34+08:00",
-    "id": 12222222,
-    "lastActionDate": "2016-10-25T01:48:34+08:00",
-    "maximumMemberCount": 5,
-    "minimumMemberCount": 0,
-    "name": "tests",
-    "regionalGroupId": 663,
-    "virtualGuestMemberTemplate": {
-        "accountId": 31111,
-        "domain": "sodg.com",
-        "hostname": "testing",
-        "id": None,
-        "maxCpu": None,
-        "maxMemory": 32768,
-        "startCpus": 32,
-        "blockDevices": [
-            {
-                "device": "0",
-                "diskImage": {
-                    "capacity": 25,
+    'accountId': 31111,
+    'balancedTerminationFlag': False,
+    'cooldown': 1800,
+    'createDate': '2018-04-30T15:07:40-04:00',
+    'desiredMemberCount': None,
+    'id': 12222222,
+    'lastActionDate': '2019-10-02T16:26:17-04:00',
+    'loadBalancers': [],
+    'maximumMemberCount': 6,
+    'minimumMemberCount': 2,
+    'modifyDate': '2019-10-03T17:16:47-04:00',
+    'name': 'tests',
+    'networkVlans': [
+        {
+            'networkVlan': {
+                'accountId': 31111,
+                'id': 2222222,
+                'modifyDate': '2019-07-16T13:09:47-04:00',
+                'networkSpace': 'PRIVATE',
+                'primaryRouter': {
+                    'hostname': 'bcr01a.sao01'
+                },
+                'primarySubnetId': 1172222,
+                'vlanNumber': 1111
+            },
+            'networkVlanId': 2281111
+        }
+    ],
+    'policies': [
+        {
+            'actions': [
+                {
+                    'amount': 1,
+                    'createDate': '2019-09-26T18:30:22-04:00',
+                    'deleteFlag': None,
+                    'id': 611111,
+                    'modifyDate': None,
+                    'scalePolicy': None,
+                    'scalePolicyId': 681111,
+                    'scaleType': 'RELATIVE',
+                    'typeId': 1
+                }
+            ],
+            'cooldown': None,
+            'createDate': '2019-09-26T18:30:14-04:00',
+            'id': 680000,
+            'name': 'prime-poly',
+            'scaleActions': [
+                {
+                    'amount': 1,
+                    'createDate': '2019-09-26T18:30:22-04:00',
+                    'deleteFlag': None,
+                    'id': 633333,
+                    'modifyDate': None,
+                    'scalePolicy': None,
+                    'scalePolicyId': 680123,
+                    'scaleType': 'RELATIVE',
+                    'typeId': 1
+                }
+            ],
+            'triggers': [
+                {
+                    'createDate': '2019-09-26T18:30:14-04:00',
+                    'deleteFlag': None,
+                    'id': 557111,
+                    'modifyDate': None,
+                    'scalePolicy': None,
+                    'scalePolicyId': 680000,
+                    'typeId': 3
                 }
+            ]
+        }
+    ],
+    'regionalGroup': {
+        'description': 'sa-bra-south-1',
+        'id': 663,
+        'locationGroupTypeId': 42,
+        'locations': [
+            {
+                'id': 983497,
+                'longName': 'Sao Paulo 1',
+                'name': 'sao01',
+                'statusId': 2
             }
         ],
-        "datacenter": {
-            "name": "sao01",
-        },
-        "hourlyBillingFlag": True,
-        "operatingSystemReferenceCode": "CENTOS_LATEST",
-        "privateNetworkOnlyFlag": True
+        'name': 'sa-bra-south-1',
+        'securityLevelId': None
     },
-    "virtualGuestMemberCount": 0,
-    "status": {
-        "id": 1,
-        "keyName": "ACTIVE",
-        "name": "Active"
+    'regionalGroupId': 663,
+    'status': {
+        'id': 1, 'keyName': 'ACTIVE', 'name': 'Active'
     },
-    "virtualGuestAssets": [],
-    "virtualGuestMembers": []
+    'suspendedFlag': False,
+    'terminationPolicy': {
+        'id': 2, 'keyName': 'NEWEST', 'name': 'Newest'
+    },
+    'terminationPolicyId': 2,
+    'virtualGuestAssets': [],
+    'virtualGuestMemberCount': 6,
+    'virtualGuestMemberTemplate': {
+        'accountId': 31111,
+        'blockDevices': [
+            {
+                'bootableFlag': None,
+                'createDate': None,
+                'device': '0',
+                'diskImage': {
+                    'capacity': 25,
+                    'createDate': None,
+                    'id': None,
+                    'modifyDate': None,
+                    'parentId': None,
+                    'storageRepositoryId': None,
+                    'typeId': None},
+                'diskImageId': None,
+                'guestId': None,
+                'hotPlugFlag': None,
+                'id': None,
+                'modifyDate': None,
+                'statusId': None
+            },
+            {
+                'bootableFlag': None,
+                'createDate': None,
+                'device': '2',
+                'diskImage': {
+                    'capacity': 10,
+                    'createDate': None,
+                    'id': None,
+                    'modifyDate': None,
+                    'parentId': None,
+                    'storageRepositoryId': None,
+                    'typeId': None},
+                'diskImageId': None,
+                'guestId': None,
+                'hotPlugFlag': None,
+                'id': None,
+                'modifyDate': None,
+                'statusId': None
+            }
+        ],
+        'createDate': None,
+        'datacenter': {
+            'id': None,
+            'name': 'sao01',
+            'statusId': None
+        },
+        'dedicatedAccountHostOnlyFlag': None,
+        'domain': 'tech-support.com',
+        'hostname': 'testing',
+        'hourlyBillingFlag': True,
+        'id': None,
+        'lastPowerStateId': None,
+        'lastVerifiedDate': None,
+        'localDiskFlag': False,
+        'maxCpu': None,
+        'maxMemory': 1024,
+        'metricPollDate': None,
+        'modifyDate': None,
+        'networkComponents': [
+            {
+                'createDate': None,
+                'guestId': None,
+                'id': None,
+                'maxSpeed': 100,
+                'modifyDate': None,
+                'networkId': None,
+                'port': None,
+                'speed': None
+            }
+        ],
+        'operatingSystemReferenceCode': 'CENTOS_LATEST',
+        'placementGroupId': None,
+        'postInstallScriptUri': 'https://test.com/',
+        'privateNetworkOnlyFlag': False,
+        'provisionDate': None,
+        'sshKeys': [
+            {
+                'createDate': None,
+                'id': 490279,
+                'modifyDate': None
+            }
+        ],
+        'startCpus': 1,
+        'statusId': None,
+        'typeId': None},
+    'virtualGuestMembers': [
+        {
+            'id': 3111111,
+            'virtualGuest': {
+
+                'domain': 'tech-support.com',
+                'hostname': 'test',
+                'provisionDate': '2019-09-27T14:29:53-04:00'
+            }
+        }
+    ]
 }
 
 scale = [


Test patch:
diff --git a/tests/CLI/modules/autoscale_tests.py b/tests/CLI/modules/autoscale_tests.py
index 33bf4a37..0c0ae92e 100644
--- a/tests/CLI/modules/autoscale_tests.py
+++ b/tests/CLI/modules/autoscale_tests.py
@@ -2,7 +2,7 @@
     SoftLayer.tests.CLI.modules.autoscale_tests
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-    Tests for the user cli command
+    Tests for the autoscale cli command
 """
 from SoftLayer import testing
 
@@ -12,3 +12,7 @@ class AutoScaleTests(testing.TestCase):
     def test_autoscale_list(self):
         result = self.run_command(['autoscale', 'list'])
         self.assert_no_fail(result)
+
+    def test_autoscale_detail(self):
+        result = self.run_command(['autoscale', 'detail', '12222222'])
+        self.assert_no_fail(result)