Skip to content

Commit c35be23

Browse files
authored
Merge pull request #233 from QuanMPhm/feature/clean_up_acct_manager
Removed references to openshift-acct-mgt
2 parents e79cc36 + 0a8d00c commit c35be23

File tree

8 files changed

+9
-82
lines changed

8 files changed

+9
-82
lines changed

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,25 @@ ESI resource allocations will only have quotas for network resources by default.
8989

9090
### Configuring for OpenShift
9191

92-
Note: OpenShift support requires deploying the [openshift-acct-mgt][]
93-
API service.
94-
95-
[openshift-acct-mgt]: https://github.com/cci-moc/openshift-acct-mgt
96-
97-
Authentication for OpenShift is loaded as pairs of environment variables
98-
`OPENSHIFT_{resource_name}_USERNAME` and `OPENSHIFT_{resource_name}_PASSWORD`
92+
Authentication for OpenShift is loaded as a environment variable
93+
`OPENSHIFT_{resource_name}_TOKEN` which should be a access token with appropriate permissions
9994
where `{resource_name}` is the name of the coldfront resource as all uppercase
10095
(with spaces and `-` replaced by `_`).
10196

10297
Each OpenShift resource must have the following attributes set in coldfront:
103-
* `OpenStack Auth URL` - the URL of the `openshift-acct-mgt` endpoint.
104-
* `OpenStack Role for User in Project` - the name of the `ClusterRole` to assign to users
98+
* `OpenShift API URL` - the URL of the Openshift cluster API.
99+
* `OpenShift Role for User in Project` - the name of the `ClusterRole` to assign to users
105100
on the namespace.
101+
* `OpenShift Identity Provider Name` - the name of the IDP configured in Openshift
106102

107103
Registration of OpenShift coldfront resources can be performed via the UI management
108104
dashboard or through the helper command:
109105

110106
```bash
111107
$ coldfront add_openshift_resource
112-
usage: coldfront add_openshift_resource [-h] --name NAME --auth-url AUTH_URL [--role ROLE] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback]
108+
usage: coldfront add_openshift_resource [-h] --name NAME --api-url API_URL --idp IDP [--role ROLE] [--for-virtualization] [--version] [-v {0,1,2,3}] [--settings SETTINGS] [--pythonpath PYTHONPATH] [--traceback]
113109
[--no-color] [--force-color] [--skip-checks]
114-
coldfront add_openshift_resource: error: the following arguments are required: --name, --auth-url
110+
coldfront add_openshift_resource: error: the following arguments are required: --name, --api-url, --idp
115111
```
116112

117113
### Quotas

ci/run_functional_tests_openshift.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
# Tests expect the resource to be name Devstack
66
set -xe
77

8-
export OPENSHIFT_MICROSHIFT_USERNAME="admin"
9-
export OPENSHIFT_MICROSHIFT_PASSWORD="pass"
108
export OPENSHIFT_MICROSHIFT_TOKEN="$(oc create token -n onboarding onboarding-serviceaccount)"
119
export OPENSHIFT_MICROSHIFT_VERIFY="false"
1210

@@ -16,7 +14,6 @@ fi
1614

1715
export DJANGO_SETTINGS_MODULE="local_settings"
1816
export FUNCTIONAL_TESTS="True"
19-
export OS_AUTH_URL="https://onboarding-onboarding.cluster.local"
2017
export OS_API_URL="https://onboarding-onboarding.cluster.local:6443"
2118

2219

src/coldfront_plugin_cloud/management/commands/add_openshift_resource.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ def add_arguments(self, parser):
2424
parser.add_argument(
2525
"--name", type=str, required=True, help="Name of OpenShift resource"
2626
)
27-
parser.add_argument(
28-
"--auth-url",
29-
type=str,
30-
required=True,
31-
help="URL of the OpenShift-acct-mgt endpoint",
32-
)
3327
parser.add_argument(
3428
"--api-url",
3529
type=str,
@@ -71,13 +65,6 @@ def handle(self, *args, **options):
7165
is_allocatable=True,
7266
)
7367

74-
ResourceAttribute.objects.get_or_create(
75-
resource_attribute_type=ResourceAttributeType.objects.get(
76-
name=attributes.RESOURCE_AUTH_URL
77-
),
78-
resource=openshift,
79-
value=options["auth_url"],
80-
)
8168
ResourceAttribute.objects.get_or_create(
8269
resource_attribute_type=ResourceAttributeType.objects.get(
8370
name=attributes.RESOURCE_API_URL

src/coldfront_plugin_cloud/openshift.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import json
33
import logging
44
import os
5-
import requests
6-
from requests.auth import HTTPBasicAuth
75
import time
8-
from simplejson.errors import JSONDecodeError
96

107
import kubernetes
118
import kubernetes.dynamic.exceptions as kexc
@@ -66,10 +63,6 @@ class NotFound(ApiException):
6663
pass
6764

6865

69-
class Conflict(ApiException):
70-
pass
71-
72-
7366
class OpenShiftResourceAllocator(base.ResourceAllocator):
7467
QUOTA_KEY_MAPPING = {
7568
attributes.QUOTA_LIMITS_CPU: lambda x: {"limits.cpu": f"{x * 1000}m"},
@@ -116,40 +109,6 @@ def k8_client(self):
116109
k8s_client = kubernetes.client.ApiClient(configuration=k8_config)
117110
return DynamicClient(k8s_client)
118111

119-
@functools.cached_property
120-
def session(self):
121-
var_name = utils.env_safe_name(self.resource.name)
122-
username = os.getenv(f"OPENSHIFT_{var_name}_USERNAME")
123-
password = os.getenv(f"OPENSHIFT_{var_name}_PASSWORD")
124-
125-
session = requests.session()
126-
if username and password:
127-
session.auth = HTTPBasicAuth(username, password)
128-
129-
functional_tests = os.environ.get("FUNCTIONAL_TESTS", "").lower()
130-
verify = os.getenv(f"OPENSHIFT_{var_name}_VERIFY", "").lower()
131-
if functional_tests == "true" or verify == "false":
132-
session.verify = False
133-
134-
return session
135-
136-
@staticmethod
137-
def check_response(response: requests.Response):
138-
if 200 <= response.status_code < 300:
139-
try:
140-
return response.json()
141-
except JSONDecodeError:
142-
# https://github.com/CCI-MOC/openshift-acct-mgt/issues/54
143-
return response.text
144-
if response.status_code == 404:
145-
raise NotFound(f"{response.status_code}: {response.text}")
146-
elif "does not exist" in response.text or "not found" in response.text:
147-
raise NotFound(f"{response.status_code}: {response.text}")
148-
elif "already exists" in response.text:
149-
raise Conflict(f"{response.status_code}: {response.text}")
150-
else:
151-
raise ApiException(f"{response.status_code}: {response.text}")
152-
153112
@staticmethod
154113
def is_error_not_found(e_info):
155114
return e_info["reason"] == "NotFound"

src/coldfront_plugin_cloud/tests/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ def new_openstack_resource(name=None, auth_url=None) -> Resource:
8080

8181
@staticmethod
8282
def new_openshift_resource(
83-
name=None, auth_url=None, api_url=None, idp=None, for_virtualization=False
83+
name=None, api_url=None, idp=None, for_virtualization=False
8484
) -> Resource:
8585
resource_name = name or uuid.uuid4().hex
8686

8787
call_command(
8888
"add_openshift_resource",
8989
name=resource_name,
90-
auth_url=auth_url or "https://onboarding-onboarding.cluster.local",
9190
api_url=api_url or "https://onboarding-onboarding.cluster.local:6443",
9291
idp=idp or "developer",
9392
for_virtualization=for_virtualization,

src/coldfront_plugin_cloud/tests/functional/openshift/test_allocation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def setUp(self) -> None:
1717
super().setUp()
1818
self.resource = self.new_openshift_resource(
1919
name="Microshift",
20-
auth_url=os.getenv("OS_AUTH_URL"),
2120
api_url=os.getenv("OS_API_URL"),
2221
)
2322

src/coldfront_plugin_cloud/tests/functional/openshift_vm/test_allocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def setUp(self) -> None:
1111
super().setUp()
1212
self.resource = self.new_openshift_resource(
1313
name="Microshift",
14-
auth_url=os.getenv("OS_AUTH_URL"),
14+
api_url=os.getenv("OS_API_URL"),
1515
for_virtualization=True,
1616
)
1717

src/coldfront_plugin_cloud/tests/unit/test_calculate_quota_unit_hours.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class TestCalculateAllocationQuotaHours(base.TestBase):
1919
def test_new_allocation_quota(self):
2020
self.resource = self.new_openshift_resource(
2121
name="",
22-
auth_url="",
2322
)
2423

2524
with freezegun.freeze_time("2020-03-15 00:01:00"):
@@ -88,7 +87,6 @@ def test_new_allocation_quota_expired(self):
8887
"""Test that expiration doesn't affect invoicing."""
8988
self.resource = self.new_openshift_resource(
9089
name="",
91-
auth_url="",
9290
)
9391
user = self.new_user()
9492
project = self.new_project(pi=user)
@@ -122,7 +120,6 @@ def test_new_allocation_quota_denied(self):
122120
"""Test a simple case of invoicing until a status change."""
123121
self.resource = self.new_openshift_resource(
124122
name="",
125-
auth_url="",
126123
)
127124
user = self.new_user()
128125
project = self.new_project(pi=user)
@@ -153,7 +150,6 @@ def test_new_allocation_quota_last_revoked(self):
153150
"""Test that we correctly distinguish the last transition to an unbilled state."""
154151
self.resource = self.new_openshift_resource(
155152
name="",
156-
auth_url="",
157153
)
158154
user = self.new_user()
159155
project = self.new_project(pi=user)
@@ -199,7 +195,6 @@ def test_new_allocation_quota_last_revoked(self):
199195
def test_new_allocation_quota_new(self):
200196
self.resource = self.new_openshift_resource(
201197
name="",
202-
auth_url="",
203198
)
204199
user = self.new_user()
205200
project = self.new_project(pi=user)
@@ -218,7 +213,6 @@ def test_new_allocation_quota_new(self):
218213
def test_new_allocation_quota_never_approved(self):
219214
self.resource = self.new_openshift_resource(
220215
name="",
221-
auth_url="",
222216
)
223217
user = self.new_user()
224218
project = self.new_project(pi=user)
@@ -241,7 +235,6 @@ def test_change_request_decrease(self):
241235
"""Test for when a change request decreases the quota"""
242236
self.resource = self.new_openshift_resource(
243237
name="",
244-
auth_url="",
245238
)
246239
user = self.new_user()
247240
project = self.new_project(pi=user)
@@ -288,7 +281,6 @@ def test_change_request_increase(self):
288281
"""Test for when a change request increases the quota"""
289282
self.resource = self.new_openshift_resource(
290283
name="",
291-
auth_url="",
292284
)
293285
user = self.new_user()
294286
project = self.new_project(pi=user)
@@ -335,7 +327,6 @@ def test_change_request_decrease_multiple(self):
335327
"""Test for when multiple different change request decreases the quota"""
336328
self.resource = self.new_openshift_resource(
337329
name="",
338-
auth_url="",
339330
)
340331
user = self.new_user()
341332
project = self.new_project(pi=user)
@@ -399,7 +390,6 @@ def test_change_request_decrease_multiple(self):
399390
def test_new_allocation_quota_change_request(self):
400391
self.resource = self.new_openshift_resource(
401392
name="",
402-
auth_url="",
403393
)
404394
user = self.new_user()
405395
project = self.new_project(pi=user)

0 commit comments

Comments
 (0)