Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Run AUNIT for GCTS repository #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions sap/adt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Connection:
"""

# pylint: disable=too-many-arguments
def __init__(self, host, client, user, password, port=None, ssl=True, verify=True):
def __init__(self, host, client, user, password=None, port=None, ssl=True, verify=True,
auth=None):
"""Parameters:
- host: string host name
- client: string SAP client
Expand Down Expand Up @@ -124,7 +125,7 @@ def __init__(self, host, client, user, password, port=None, ssl=True, verify=Tru
self._base_url = f'{protocol}://{host}:{port}/{self._adt_uri}'
self._query_args = f'sap-client={client}&saml2=disabled'
self._user = user
self._auth = HTTPBasicAuth(user, password)
self._auth = auth if auth else HTTPBasicAuth(user, password)
self._session = None
self._collection_types = None
self._timeout = config_get('http_timeout')
Expand Down
6 changes: 5 additions & 1 deletion sap/adt/object_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def __init__(self, connection: sap.adt.core.Connection, builders: Optional[ADTOb
if builders:
self._builders = builders
else:
self._builders = cast(ADTObjectBuilderDictType, {})
self._builders = cast(ADTObjectBuilderDictType, {
'CLAS': sap.adt.Class,
'FUGR': sap.adt.FunctionGroup,
'PROG': sap.adt.Program,
})

def register(self, typ: str, producer: ADTObjectBuilderType, overwrite: bool = False) -> None:
"""Registers ADT object builder"""
Expand Down
34 changes: 34 additions & 0 deletions sap/cli/gcts.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,40 @@ def install_parser(self, arg_parser):
self.branch_grp.install_parser(branch_parser)


@RepoCommandGroup.argument('package')
@RepoCommandGroup.command('run-aunit')
def run_aunit(connection, args):
"""Run AUNIT for GCTS repository"""

adt_connection = connection.get_adt_connection()
repo = get_repository(connection, args.package)
objects = repo.list_objects()
# remove object type DEVC, because it is already included in scope packages
# also if you run ATC Checks for DEVC together with other object types, ATC checks will run only for DEVC
# SUSH is removed because this type is not supported yet
objects = [obj for obj in objects if obj['type'] != 'DEVC' and obj['type'] != 'SUSH']
objfactory = sap.adt.object_factory.ADTObjectFactory(adt_connection)

sets = sap.adt.objects.ADTObjectSets()

for obj in objects:
objname = obj['object']
objtype = obj['type']
try:
sets.include(objfactory.make(objtype, objname))
except SAPCliError as ex:
sap.cli.core.printerr(str(ex))
return 1

aunit = sap.adt.AUnit(adt_connection)
aunit_response = aunit.execute(sets)
if aunit_response.status_code != 200:
print('AUNIT fail:', aunit_response.text)
return 1

return 0


@RepoCommandGroup.argument('url')
@RepoCommandGroup.argument('package')
@RepoCommandGroup.command('set-url')
Expand Down
9 changes: 9 additions & 0 deletions sap/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
from requests.auth import HTTPBasicAuth

import sap.adt.core
from sap import get_logger, config_get
from sap.rest.errors import (
HTTPRequestError,
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(self, icf_path, login_path, host, client, user, password, port=None
self._session = None
self._login_path = login_path
self._timeout = config_get('http_timeout')
self._client = client

@property
def user(self):
Expand Down Expand Up @@ -242,3 +244,10 @@ def delete_json(self, uri_path, params=None):

response = self.execute('DELETE', uri_path, accept='application/json', params=params)
return response.json()

def get_adt_connection(self):
"""Build ADT Connection from this connection.
"""

return sap.adt.core.Connection(self._host, self._client, self._user, port=self._port, ssl=self._ssl,
verify=self._ssl_verify, auth=self._auth)
7 changes: 7 additions & 0 deletions sap/rest/gcts/remote_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,10 @@ def list_branches(self):
raise SAPCliError("gCTS response does not contain 'branches'")

return branches

def list_objects(self):
"""List ADT objects of repository"""

response = self._http.get_json('objects')

return response['objects']
Loading