Skip to content

Commit 97ebf39

Browse files
authored
Merge pull request #48 from hpe-container-platform-community/add_flake8_check_to_travis
add flake8 build stage
2 parents 5503387 + 6614af8 commit 97ebf39

File tree

2 files changed

+101
-57
lines changed

2 files changed

+101
-57
lines changed

.travis.yml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ python:
66
- "3.7"
77
- "3.8"
88
- "3.9-dev"
9-
install:
9+
install:
1010
- pip install tox-travis
1111
- pip install python-coveralls
1212
- pip install coverage==4.5.4
@@ -23,18 +23,24 @@ after_success:
2323

2424
jobs:
2525
include:
26+
- stage: flake8
27+
name: "Flake8 code checks"
28+
python: 3.8
29+
install:
30+
- pip3 install flake8 # TODO: install 'flake8-docstrings'
31+
script:
32+
- flake8 bin/ # TODO: add docstring 'flake8 --docstring-convention numpy hpecp/ bin/ tests/'
2633
- stage: format
2734
name: "Check code formatting"
2835
python: 3.8
29-
install:
36+
install:
3037
- pip3 install black
3138
script:
32-
- black --check hpecp/
33-
- black --check tests/
34-
- black --check bin/
39+
- black --check hpecp/ tests/ bin/
3540
- stage: deploy
41+
if: branch = master
3642
python: 3.8
37-
install:
43+
install:
3844
- pip install tox-travis
3945
- pip install python-coveralls
4046
- pip install coverage==4.5.4
@@ -47,11 +53,11 @@ jobs:
4753
- make html
4854
- touch ./build/html/.nojekyll
4955
deploy:
50-
provider: pages
51-
skip_cleanup: true
52-
github_token:
53-
secure: h+fqasd4ZOdm0IxVRQVl3IKmENIB3AB5IeVSNK7J35LMG+/QzaZD26naD0CVfa7RbGeKv9EpV91f3SHR/SikY0l+IA2OT0607SWdDYxFYrbrPzEwG8N72UwwcCCO2hfscE68krRYt2zDoWY7chZeJsAHTcL0l5ap2k34AYiDnBUW1PffgAGoVLbBH1dcTRi3pYCx0rbsQYv06D3wkuGF/Yin04uuxFaE+aLIfKxJVAeeiKcsPEzVyZHDOI08r6lzRjtjT+p1HOgnPH08pLcHdpRC0lP9RK/xCPvbhj5zS0PnDqcbYjpWpLK1Jg8MzLaHTo3223ygMmiNLXZptb6anfuulLBpzYLetgLF4QZsQYQfkY/IdtGVR2oWtq+0v54qFeSOH88SQPqOtyKTj0WlBT343y+DoVbhLNKvSmxiWFE/fr2b7VXYqF/gllZHZdQ2WQfI1F/lHeWZtScZaRK5sq7ofyecCpNy+Hw55F2i1Q+YTdJD8VtD/Zmz3j+OTW6uMUKPxnBrHnK6hjrrTg/t+mVhP7Ui4voEuiv5SSdTwGd4iYLdFpOchmduGW0mRzAeES+TOExpWmLnYKkKgQ1XiZ4rX6woZNIVAk0wTHzl2DpYaCpDHYwhNlzIyLD0j4gmwdlE4JD5Ut1YLr+gnMcoLMxPLY96vMohRI0WML+38O0=
54-
keep-history: true
55-
on:
56-
branch: master
57-
local_dir: docs/build/html
56+
provider: pages
57+
skip_cleanup: true
58+
github_token:
59+
secure: h+fqasd4ZOdm0IxVRQVl3IKmENIB3AB5IeVSNK7J35LMG+/QzaZD26naD0CVfa7RbGeKv9EpV91f3SHR/SikY0l+IA2OT0607SWdDYxFYrbrPzEwG8N72UwwcCCO2hfscE68krRYt2zDoWY7chZeJsAHTcL0l5ap2k34AYiDnBUW1PffgAGoVLbBH1dcTRi3pYCx0rbsQYv06D3wkuGF/Yin04uuxFaE+aLIfKxJVAeeiKcsPEzVyZHDOI08r6lzRjtjT+p1HOgnPH08pLcHdpRC0lP9RK/xCPvbhj5zS0PnDqcbYjpWpLK1Jg8MzLaHTo3223ygMmiNLXZptb6anfuulLBpzYLetgLF4QZsQYQfkY/IdtGVR2oWtq+0v54qFeSOH88SQPqOtyKTj0WlBT343y+DoVbhLNKvSmxiWFE/fr2b7VXYqF/gllZHZdQ2WQfI1F/lHeWZtScZaRK5sq7ofyecCpNy+Hw55F2i1Q+YTdJD8VtD/Zmz3j+OTW6uMUKPxnBrHnK6hjrrTg/t+mVhP7Ui4voEuiv5SSdTwGd4iYLdFpOchmduGW0mRzAeES+TOExpWmLnYKkKgQ1XiZ4rX6woZNIVAk0wTHzl2DpYaCpDHYwhNlzIyLD0j4gmwdlE4JD5Ut1YLr+gnMcoLMxPLY96vMohRI0WML+38O0=
60+
keep-history: true
61+
on:
62+
branch: master
63+
local_dir: docs/build/html

bin/cli.py

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@
6767
if "HPECP_CONFIG_FILE" in os.environ:
6868
HPECP_CONFIG_FILE = os.getenv("HPECP_CONFIG_FILE")
6969
_log.debug(
70-
"HPECP_CONFIG_FILE envirionment variable exists with value '{}'".format(
70+
"HPECP_CONFIG_FILE env variable exists with value '{}'".format(
7171
HPECP_CONFIG_FILE
7272
)
7373
)
7474
else:
7575
HPECP_CONFIG_FILE = "~/.hpecp.conf"
7676
_log.debug(
77-
"HPECP_CONFIG_FILE envirionment variable not found, setting to '{}'".format(
77+
"HPECP_CONFIG_FILE env variable not found, setting to '{}'".format(
7878
HPECP_CONFIG_FILE
7979
)
8080
)
8181

8282

8383
def get_client():
84-
"""Utility function to retrieve an authenticated client object"""
84+
"""Utility function to retrieve an authenticated client object."""
8585
try:
8686
client = ContainerPlatformClient.create_from_config_file(
8787
config_file=HPECP_CONFIG_FILE, profile=PROFILE,
@@ -114,10 +114,14 @@ def create_with_ssh_key(
114114
):
115115
"""Create a Gateway using SSH key authentication
116116
117-
:param ip: The IP address of the proxy host. Used for internal communication.
118-
:param proxy_node_hostname: Clients will access cluster services will be accessed using this name.
119-
:param ssh_key: The ssh key data as a string. Alternatively, use the ssh_key_file parameter.
120-
:param ssh_key_file: The file path to the ssh key. Alternatively, use the ssh_key parameter.
117+
:param ip: The IP address of the proxy host. Used for internal
118+
communication.
119+
:param proxy_node_hostname: Clients will access cluster services will
120+
be accessed using this name.
121+
:param ssh_key: The ssh key data as a string. Alternatively, use the
122+
ssh_key_file parameter.
123+
:param ssh_key_file: The file path to the ssh key. Alternatively, use
124+
the ssh_key parameter.
121125
:param tags: Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
122126
"""
123127

@@ -154,7 +158,8 @@ def get(
154158
):
155159
"""Retrieve a Gateway by Id
156160
157-
:param gateway_id: the id of the gateway with format: '/api/v1/workers/[0-9]+'
161+
:param gateway_id: the id of the gateway with format:
162+
'/api/v1/workers/[0-9]+'
158163
:param output: how to display the output ['yaml'|'json']
159164
"""
160165
response = get_client().gateway.get(gateway_id)
@@ -172,6 +177,7 @@ def get(
172177
def list(
173178
self, output="table", columns=Gateway.default_display_fields, query={}
174179
):
180+
175181
"""Retrieve the list of Gateways
176182
177183
:param output: how to display the output [text|table|json]
@@ -180,12 +186,15 @@ def list(
180186
Example::
181187
182188
> hpecp gateway list --output json --query '[0].ip'
189+
183190
10.1.0.185
184-
185-
> hpecp gateway list --output json --query '[*].[ip, purpose, state, hostname]'
186-
[['10.1.0.185', 'proxy', 'installed', 'ip-10-1-0-185.us-west-2.compute.internal']]
187-
188-
"""
191+
192+
> hpecp gateway list --output json --query
193+
'[*].[ip, purpose, state, hostname]'
194+
195+
[['10.1.0.185', 'proxy', 'installed',
196+
'ip-10-1-0-185.us-west-2.compute.internal']]
197+
""" # noqa: W293
189198
if output == "table":
190199
print(get_client().gateway.list().tabulate(columns=columns))
191200
elif output == "text":
@@ -208,8 +217,10 @@ def delete(
208217
):
209218
"""Retrieve a Gateway by Id
210219
211-
:param gateway_id: the id of the gateway with format: '/api/v1/workers/[0-9]+'
212-
:param wait_for_delete_secs: if 0 return immediately after calling delete
220+
:param gateway_id: the id of the gateway with format:
221+
'/api/v1/workers/[0-9]+'
222+
:param wait_for_delete_secs: if 0 return immediately after calling
223+
delete
213224
214225
wait_for_delete_secs > 0 `calls wait_for_delete()`
215226
"""
@@ -243,9 +254,11 @@ def wait_for_state(
243254
"""
244255
Wait for Gateway to have one or more statuses
245256
:param gateway_id: Cluster id with format: /api/v1/workers/[0-9]+
246-
:param status: status(es) to wait for with format: ['status1', 'status2', 'statusn'] - set to [] to wait for item to be deleted
257+
:param status: status(es) to wait for with format: ['status1',
258+
'status2', 'statusn'] - set to [] to wait for item to be deleted
247259
:param timeout_secs: how many secs to wait before exiting
248-
:returns True/False if status was found within timeout_secs. May raise APIException.
260+
:returns True/False if status was found within timeout_secs. May raise
261+
APIException.
249262
250263
See also: `hpecp gateway states`
251264
"""
@@ -277,9 +290,12 @@ def create_with_ssh_key(
277290
):
278291
"""Create a K8s Worker using SSH key authentication
279292
280-
:param ip: The IP address of the host. Used for internal communication.
281-
:param ssh_key: The ssh key data as a string. Alternatively, use the ssh_key_file parameter.
282-
:param ssh_key_file: The file path to the ssh key. Alternatively, use the ssh_key parameter.
293+
:param ip: The IP address of the host. Used for internal
294+
communication.
295+
:param ssh_key: The ssh key data as a string. Alternatively, use the
296+
ssh_key_file parameter.
297+
:param ssh_key_file: The file path to the ssh key. Alternatively, use
298+
the ssh_key parameter.
283299
:param tags: Tags to use, e.g. "{ 'tag1': 'foo', 'tag2', 'bar' }".
284300
"""
285301
if ssh_key is None and ssh_key_file is None:
@@ -326,16 +342,20 @@ def list(
326342
> hpecp k8sworker list --output json --query '[0].ip'
327343
10.1.0.185
328344
329-
> hpecp k8sworker list --output json --query "[*].[status, hostname, ipaddr]"
330-
[['configured', 'ip-10-1-0-72.us-west-2.compute.internal', '10.1.0.72'],
331-
['configured', 'ip-10-1-0-238.us-west-2.compute.internal', '10.1.0.238']]
345+
> hpecp k8sworker list --output json --query "[*].[status, hostname,
346+
ipaddr]"
347+
348+
[['configured', 'ip-10-1-0-72.us-west-2.compute.internal', '10.1.0.72']
349+
,['configured', 'ip-10-1-0-238.us-west-2.compute.internal',
350+
'10.1.0.238']]
332351
333352
# Using jq to convert the json output to a table
334-
> hpecp k8sworker list --output json --query "[*].[status, hostname, ipaddr]" | jq -r '.[] | @csv'
353+
> hpecp k8sworker list --output json --query "[*].[status, hostname,
354+
ipaddr]" | jq -r '.[] | @csv'
335355
"configured","ip-10-1-0-72.us-west-2.compute.internal","10.1.0.72"
336356
"configured","ip-10-1-0-238.us-west-2.compute.internal","10.1.0.238"
337357
338-
"""
358+
""" # noqa: W293
339359
if output == "table":
340360
print(get_client().k8s_worker.list().tabulate(columns=columns))
341361
elif output == "text":
@@ -380,8 +400,10 @@ def set_storage(
380400
"""Set Storage
381401
382402
:param k8sworker_id: the worker ID
383-
:param persistent_disks: a comma separated list of zero or more persistent disks, e.g. "/dev/nvme2n1"
384-
:param ephemeral_disks: a comma separated list of zero or more ephemeral_disks disks, e.g. "/dev/nvme1n1"
403+
:param persistent_disks: a comma separated list of zero or more
404+
persistent disks, e.g. "/dev/nvme2n1"
405+
:param ephemeral_disks: a comma separated list of zero or more
406+
ephemeral_disks disks, e.g. "/dev/nvme1n1"
385407
"""
386408

387409
p_disks = persistent_disks.split(",")
@@ -399,9 +421,11 @@ def wait_for_status(
399421
"""
400422
Wait for Worker to have one or more statuses
401423
:param worker_id: Worker id with format: /api/v1/workers/[0-9]+
402-
:param status: status(es) to wait for with format: ['status1', 'status2', 'statusn'] - set to [] to wait for item to be deleted
424+
:param status: status(es) to wait for with format: ['status1',
425+
'status2', 'statusn'] - set to [] to wait for item to be deleted
403426
:param timeout_secs: how many secs to wait before exiting
404-
:returns True/False if status was found within timeout_secs. May raise APIException.
427+
:returns True/False if status was found within timeout_secs. May raise
428+
APIException.
405429
406430
See also: `hpecp k8sworker states`
407431
"""
@@ -447,11 +471,14 @@ def create(
447471
"""Create a K8s Cluster
448472
449473
:param name: the cluster name
450-
:param k8shosts_config: k8s host ids and roles 'id1:master|worker,id2:master|worker,...'
474+
:param k8shosts_config: k8s host ids and roles 'id1:master|worker,id2:
475+
master|worker,...'
451476
:param description: the cluster descripton
452477
:param k8s_version: e.g. 1.17.0
453-
:param pod_network_range: the pod network range, default='10.192.0.0/12'
454-
:param service_network_range: the service network range, default='10.96.0.0/12'
478+
:param pod_network_range: the pod network range,
479+
default='10.192.0.0/12'
480+
:param service_network_range: the service network range,
481+
default='10.96.0.0/12'
455482
:param pod_dns_domain: the pod dns domain, default='cluster.local'
456483
:param persistent_storage_local: True/False
457484
:param persistent_storage_nimble_csi: True/False
@@ -570,9 +597,11 @@ def wait_for_status(
570597
"""
571598
Wait for K8s Cluster to have one or more statuses
572599
:param k8scluster_id: Cluster id with format: /api/v2/k8scluster/[0-9]+
573-
:param status: status(es) to wait for with format: ['status1', 'status2', 'statusn']
600+
:param status: status(es) to wait for with format:
601+
['status1', 'status2', 'statusn']
574602
:param timeout_secs: how many secs to wait before exiting
575-
:returns True/False if status was found within timeout_secs. May raise APIException.
603+
:returns True/False if status was found within timeout_secs. May
604+
raise APIException.
576605
"""
577606
cluster_status = [K8sClusterStatus[s] for s in status]
578607

@@ -582,7 +611,7 @@ def wait_for_status(
582611
status=cluster_status,
583612
timeout_secs=timeout_secs,
584613
)
585-
except:
614+
except Exception:
586615
success = False
587616

588617
if not success:
@@ -614,7 +643,8 @@ def k8s_supported_versions(
614643
615644
Example::
616645
617-
hpecp k8scluster k8s_supported_versions --major-filter 1 --minor-filter 17
646+
hpecp k8scluster k8s_supported_versions --major-filter 1
647+
--minor-filter 17
618648
"""
619649
assert output in [
620650
"json",
@@ -739,7 +769,8 @@ def register(
739769
):
740770
"""Register a license
741771
742-
:param server_filename: Filepath to the license on the server, e.g. '/srv/bluedata/license/LICENSE-1.txt'
772+
:param server_filename: Filepath to the license on the server, e.g.
773+
'/srv/bluedata/license/LICENSE-1.txt'
743774
"""
744775
get_client().license.register(server_filename=server_filename)
745776
print("Done.")
@@ -763,7 +794,8 @@ def upload_with_ssh_key(
763794
- run client.license.register(server_filename) to register the license
764795
"""
765796
raise Exception(
766-
"Not implemented yet! Workaround: scp your license to '/srv/bluedata/license/'"
797+
"Not implemented yet! Workaround: scp your license to"
798+
"'/srv/bluedata/license/'"
767799
)
768800

769801
def upload_with_ssh_pass(
@@ -785,17 +817,20 @@ def upload_with_ssh_pass(
785817
- run client.license.register(server_filename) to register the license
786818
"""
787819
raise Exception(
788-
"Not implemented yet! Workaround: scp your license to '/srv/bluedata/license/'"
820+
"Not implemented yet! Workaround: scp your license to"
821+
"'/srv/bluedata/license/'"
789822
)
790823

791824
def delete(
792825
self, license_key,
793826
):
794827
"""Delete a license by LicenseKey
795828
796-
:param license_key: The license key, e.g. '1234 1234 ... 1234 "SOMETEXT"'
829+
:param license_key: The license key, e.g. '1234 1234 ... 1234
830+
"SOMETEXT"'
797831
798-
TIP: use `hpecp license list --license_key_only True` to get the license key
832+
TIP: use `hpecp license list --license_key_only True` to get the
833+
license key
799834
"""
800835
get_client().license.delete(license_key=license_key)
801836
print("Delete submitted - verify with: `hpecp license list`")
@@ -882,7 +917,7 @@ def put(
882917
Example:
883918
884919
hpecp httpclient put /api/v2/config/auth --json-file my.json
885-
"""
920+
""" # noqa: W293
886921
with open(json_file, "r",) as f:
887922
data = json.load(f)
888923

@@ -1037,7 +1072,7 @@ def bash(self,):
10371072
10381073
} &&
10391074
complete -F _hpecp_complete hpecp
1040-
"""
1075+
""" # noqa: E501
10411076
)
10421077

10431078

@@ -1063,6 +1098,9 @@ def configure_cli():
10631098
controller_username = config_reader.username
10641099
controller_password = config_reader.password
10651100

1101+
if sys.version_info[0] >= 3:
1102+
raw_input = input
1103+
10661104
sys.stdout.write("Controller API Host [{}]: ".format(controller_api_host))
10671105
tmp = raw_input()
10681106
if tmp != "":

0 commit comments

Comments
 (0)