-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add-registry-sidecar-support
- Loading branch information
Showing
22 changed files
with
514 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: CI-Code-Style | ||
|
||
on: [push] | ||
|
||
jobs: | ||
unit_tests: | ||
name: Linter checks | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
matrix: | ||
python-version: [3.6] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Python${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Tox | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install tox | ||
- name: Run code checks | ||
run: | | ||
tox -e check | ||
tox -e "unit_py${PY_VER/./_}" -- -n auto | ||
env: | ||
PY_VER: ${{ matrix.python-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Distribution / packaging | ||
*.egg-info | ||
|
||
# Unit test / coverage reports | ||
.tox/ | ||
.coverage | ||
.cache | ||
**/*/__pycache__/ | ||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-r .virtualenv.requirements.txt | ||
|
||
# python unit testing framework | ||
pytest | ||
pytest-cov | ||
coverage | ||
|
||
# Rolling backport of unittest.mock for all Pythons | ||
mock | ||
|
||
# Python style guide checker | ||
flake8 | ||
|
||
# Version-bump your software with a single command! | ||
bumpversion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
lxml | ||
requests | ||
dnspython | ||
M2Crypto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
10.1.6 | ||
10.1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.\" Process this file with | ||
.\" groff -man -Tascii cloudguestregstryauth.1 | ||
.\" | ||
.TH cloudguestregstryauth.1 | ||
.SH NAME | ||
cloudguestregstryauth \- Refresh registry credentials for a registered SUSE Linux Enterprise instance | ||
.SH SYNOPSIS | ||
.B cloudguestregstryauth | ||
.SH DESCRIPTION | ||
.B cloudguestregstryauth | ||
Refresh registry credentials for a registered SUSE Linux Enterprise instance. The client will reach | ||
out to the already configured update server to refresh the existing credentials. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[server] | ||
api = regionInfo | ||
certLocation = /var/lib/regionService/certs | ||
certLocation = /usr/lib/regionService/certs | ||
regionsrv = COMMA_SEP_LIST_OF_CLOUD_SPECIFIC_REGION_SERVER | ||
metadata_server = OPTIONAL_URL_FOR_METADATA_SERVER_SMT_INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import inspect | ||
import os | ||
import sys | ||
|
||
from lxml import etree | ||
|
||
from cloudregister.smt import SMT | ||
from importlib.machinery import SourceFileLoader | ||
|
||
from pytest import raises | ||
from textwrap import dedent | ||
from unittest.mock import patch | ||
|
||
test_path = os.path.abspath( | ||
os.path.dirname(inspect.getfile(inspect.currentframe()))) | ||
code_path = os.path.abspath('%s/../lib' % test_path) | ||
data_path = test_path + os.sep + 'data/' | ||
|
||
sys.path.insert(0, code_path) | ||
|
||
# Hack to get the script without the .py imported for testing | ||
cloudguestregistryauth = SourceFileLoader( | ||
'cloudguestregistryauth', | ||
'./usr/bin/cloudguestregistryauth' | ||
).load_module() | ||
|
||
|
||
@patch('cloudguestregistryauth.os.geteuid') | ||
def test_registry_call_as_root(mock_os_geteuid): | ||
mock_os_geteuid.return_value = 1 | ||
with raises(SystemExit) as pytest_wrapped_e: | ||
cloudguestregistryauth.main() | ||
|
||
assert pytest_wrapped_e.type == SystemExit | ||
assert pytest_wrapped_e.value.code == 'You must be root' | ||
|
||
|
||
@patch('cloudregister.registerutils.get_activations') | ||
@patch('cloudregister.registerutils.is_registered') | ||
@patch('cloudregister.registerutils.get_current_smt') | ||
@patch('cloudguestregistryauth.os.geteuid') | ||
def test_registry_get_activations_error( | ||
mock_os_geteuid, mock_get_current_smt, | ||
mock_is_registered, mock_get_activations | ||
): | ||
mock_os_geteuid.return_value = 0 | ||
mock_is_registered.return_value = True | ||
smt_data_ipv46 = dedent('''\ | ||
<smtInfo fingerprint="00:11:22:33" | ||
SMTserverIP="192.168.1.1" | ||
SMTserverIPv6="fc00::1" | ||
SMTserverName="fantasy.example.com" | ||
SMTregistryName="registry-fantasy.example.com" | ||
region="antarctica-1"/>''') | ||
smt_server = SMT(etree.fromstring(smt_data_ipv46)) | ||
mock_get_current_smt.return_value = smt_server | ||
mock_get_activations.return_value = {} | ||
|
||
with raises(SystemExit) as pytest_wrapped_e: | ||
cloudguestregistryauth.main() | ||
|
||
assert pytest_wrapped_e.type == SystemExit | ||
assert pytest_wrapped_e.value.code == 'Could not refresh credentials' | ||
|
||
|
||
@patch('builtins.print') | ||
@patch('cloudregister.registerutils.get_activations') | ||
@patch('cloudregister.registerutils.is_registered') | ||
@patch('cloudregister.registerutils.get_current_smt') | ||
@patch('cloudguestregistryauth.os.geteuid') | ||
def test_registry_get_activations( | ||
mock_os_geteuid, mock_get_current_smt, | ||
mock_is_registered, mock_get_activations, | ||
mock_print | ||
): | ||
mock_os_geteuid.return_value = 0 | ||
mock_is_registered.return_value = True | ||
smt_data_ipv46 = dedent('''\ | ||
<smtInfo fingerprint="00:11:22:33" | ||
SMTserverIP="192.168.1.1" | ||
SMTserverIPv6="fc00::1" | ||
SMTserverName="fantasy.example.com" | ||
SMTregistryName="registry-fantasy.example.com" | ||
region="antarctica-1"/>''') | ||
smt_server = SMT(etree.fromstring(smt_data_ipv46)) | ||
mock_get_current_smt.return_value = smt_server | ||
mock_get_activations.return_value = {'foo': 'bar'} | ||
|
||
cloudguestregistryauth.main() | ||
mock_print.assert_called_once_with('Credentials refreshed') |
Oops, something went wrong.