Skip to content

Commit f1838f7

Browse files
author
Fernando Ojeda
committed
Refactor cdn network.
1 parent 9ceccb1 commit f1838f7

File tree

6 files changed

+51
-66
lines changed

6 files changed

+51
-66
lines changed

SoftLayer/CLI/cdn/load.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"originType": "HOST_SERVER",
2929
"path": "/example",
3030
"status": "RUNNING",
31+
"bucketName": "test-bucket",
32+
'fileExtension': 'jpg',
3133
"performanceConfiguration": "General web delivery"
3234
}
3335
]

SoftLayer/fixtures/SoftLayer_Network_ContentDelivery_Account.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

SoftLayer/managers/cdn.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def add_origin(self, unique_id, origin, path, origin_type="server", header=None,
9696
'uniqueId': unique_id,
9797
'path': path,
9898
'origin': origin,
99-
'originType': types.get(origin_type, 'HOST_SERVER'),
99+
'originType': types.get(origin_type),
100100
'httpPort': port,
101101
'protocol': protocol.upper(),
102102
'performanceConfiguration': performance_config.get(optimize_for, 'General web delivery'),
@@ -109,8 +109,6 @@ def add_origin(self, unique_id, origin, path, origin_type="server", header=None,
109109
if types.get(origin_type) == 'OBJECT_STORAGE':
110110
if bucket_name:
111111
new_origin['bucketName'] = bucket_name
112-
else:
113-
raise exceptions.SoftLayerError("Bucket name is required when the origin type is OBJECT_STORAGE")
114112

115113
if file_extensions:
116114
new_origin['fileExtension'] = file_extensions

tests/CLI/modules/cdn_tests.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88

99
from SoftLayer import testing
10+
from SoftLayer.CLI import exceptions
1011

1112

1213
class CdnTests(testing.TestCase):
@@ -61,9 +62,30 @@ def test_list_origins(self):
6162
'Path': '/example1',
6263
'Status': 'RUNNING'}])
6364

64-
def test_add_origin(self):
65-
result = self.run_command(['cdn', 'origin-add', '-H=test.example.com', '-p', 80, '-o', 'web', '-c=include-all',
66-
'1234', '10.10.10.1', '/example/videos2'])
65+
def test_add_origin_server(self):
66+
result = self.run_command(
67+
['cdn', 'origin-add', '-t', 'server', '-H=test.example.com', '-p', 80, '-o', 'web', '-c=include-all',
68+
'1234', '10.10.10.1', '/example/videos2'])
69+
70+
self.assert_no_fail(result)
71+
72+
def test_add_origin_storage(self):
73+
result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-H=test.example.com',
74+
'-p', 80, '-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2'])
75+
76+
self.assert_no_fail(result)
77+
78+
def test_add_origin_without_storage(self):
79+
result = self.run_command(['cdn', 'origin-add', '-t', 'storage', '-H=test.example.com', '-p', 80,
80+
'-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2'])
81+
82+
self.assertEqual(result.exit_code, 2)
83+
self.assertIsInstance(result.exception, exceptions.ArgumentError)
84+
85+
def test_add_origin_storage_with_file_extensions(self):
86+
result = self.run_command(
87+
['cdn', 'origin-add', '-t', 'storage', '-b=test-bucket', '-e', 'jpg', '-H=test.example.com', '-p', 80,
88+
'-o', 'web', '-c=include-all', '1234', '10.10.10.1', '/example/videos2'])
6789

6890
self.assert_no_fail(result)
6991

tests/managers/cdn_tests.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
:license: MIT, see LICENSE for more details.
66
"""
77

8-
from SoftLayer.managers import cdn
98
from SoftLayer import testing
109
from SoftLayer import utils
10+
from SoftLayer.managers import cdn
1111

1212

1313
class CDNTests(testing.TestCase):
@@ -70,6 +70,28 @@ def test_add_origin(self):
7070
'createOriginPath',
7171
args=args)
7272

73+
def test_add_origin_with_bucket_and_file_extension(self):
74+
self.cdn_client.add_origin("12345", "10.10.10.1", "/example/videos", origin_type="storage",
75+
bucket_name="test-bucket", file_extensions="jpg", header="test.example.com", port=80,
76+
protocol='http', optimize_for="web", cache_query="include all")
77+
78+
args = ({
79+
'uniqueId': "12345",
80+
'origin': '10.10.10.1',
81+
'path': '/example/videos',
82+
'originType': 'OBJECT_STORAGE',
83+
'header': 'test.example.com',
84+
'httpPort': 80,
85+
'protocol': 'HTTP',
86+
'bucketName': 'test-bucket',
87+
'fileExtension': 'jpg',
88+
'performanceConfiguration': 'General web delivery',
89+
'cacheKeyQueryRule': "include all"
90+
},)
91+
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
92+
'createOriginPath',
93+
args=args)
94+
7395
def test_remove_origin(self):
7496
self.cdn_client.remove_origin("12345", "/example1")
7597

0 commit comments

Comments
 (0)