Skip to content

Commit d3059e2

Browse files
authored
Merge branch 'main' into 228-add-ignore-scripts-argument-sonarqube
2 parents c6a11a0 + 8a541ed commit d3059e2

File tree

12 files changed

+286
-136
lines changed

12 files changed

+286
-136
lines changed

.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This .env file is used by all compose commands for test and development usage.
2+
# NOTE: Production deployments via Puppet use an alternative version of this file generated by the tools.
3+
4+
# Choose which profile(s) to run.
5+
# If no profiles are set, a 'light' configuration will be started without the UI components
6+
# Available profiles include 'full' (UI) and 'dev' (aeveloper tools such as adminer)
7+
COMPOSE_PROFILES=full,dev
8+
19
# Port Services; Uncomment below lines to override default mappings
210
#AUTHNZ_PORT=8084
311
#AUTHNZ_HTTPS_PORT=8443

.github/workflows/anms-core.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,34 @@ jobs:
3030
run: |
3131
FAIL_SRC=0
3232
flake8 src || FAIL_SRC=$?
33+
anms-core_integration-test:
34+
runs-on: ubuntu-24.04
35+
env:
36+
ANMS_COMPOSE_OPTS: -f docker-compose.yml --profile light
37+
TEST_COMPOSE_OPTS: -f anms-core/integration_test/docker-compose.yml
38+
HOST_SOCKDIR: sockdir
39+
CTR_SOCKDIR: /var/tmp/nm
40+
DOCKER_CMD: docker
41+
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
with:
45+
submodules: recursive
46+
- name: Build ANMS
47+
run: docker compose ${ANMS_COMPOSE_OPTS} build
48+
- name: Build TEST
49+
run: docker compose ${TEST_COMPOSE_OPTS} build
50+
- name: Build Volume
51+
run: |
52+
./create_volume.sh ./puppet/modules/apl_test/files/anms/tls
53+
sudo mkdir /run/anms
54+
- name: run
55+
run: |
56+
docker compose ${ANMS_COMPOSE_OPTS} up -d --force-recreate --wait --wait-timeout 600
57+
docker compose ${TEST_COMPOSE_OPTS} run test-fixture
58+
- name: after_script
59+
run: |
60+
if [ "${CI_JOB_STATUS}" = 'failed' ]; then
61+
docker logs anms-core
62+
fi
63+

README.md

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ If your computer is behind a network proxy, this may cause issues related to usi
4949
Though ANMS can be run behind a proxy; building the ANMS Docker images from behind a network proxy may result in errors.
5050

5151
The first steps in each of the container image `Dockerfile` is to attempt to download an APLNIS root CA to validate the APLNIS HTTPS proxy.
52-
When building images outside of the APLNIS, this download will gracefully fail and the image will not be able to run within the APLNIS.
52+
When building images outside of the APLNIS, this download will gracefully fail and the image will not be able to run within the APLNIS. The URL for this certificate can be changed for users requiring equivalent functionality on their own networks.
53+
54+
### Special Notes on Podman
55+
56+
If not otherwise specified, most commands in this document allow podman and docker to be used interchangeably. It is also possible to install an alias (provided in most package managers) to map `docker` to `podman` if desired.
57+
58+
Podman, running as a standard user, is typically unable to bind to **low-numbered ports**. It is recommended to edit the `.env` file and uncomment the lines at top for AUTHNZ_PORT and AUTHNZ_HTTPS_PORT to remap those services to a higher port number. In the directions below, you would then use for example http://localhost:8084 and https://localhost:8443 instead of the default.
59+
60+
Note: If running on a system where **SELinux** is enabled, the system will not start if the appropriate security groups have not been defined. As an alternative, the `security_opt` sections can be commented out in the *-compose.yml files if required.
61+
5362

5463
### Upgrading ANMS
5564

@@ -63,29 +72,35 @@ The following command sequence uses standard Docker commands to stop all contain
6372
docker stop $(docker ps -q); docker rm $(docker ps --all -q); docker system prune -f; docker volume prune -f
6473
```
6574

66-
### Deployment Scenario
67-
68-
The current ANMS capability is designed to run on `localhost` and on a development virtual machine.
69-
This guide presumes that you can either connect via a VMRC remote console or with ssh tunnelling to the machine, hence the use of `localhost` in db connection information and in URLs.
70-
If you deploy this to a VM, you will need to replace `localhost` with the hostname of the machine where it is deployed.
7175

72-
### Special Notes on Podman
76+
## ANMS build and deploy
7377

74-
If not otherwise specified, most commands in this document allow podman and docker to be used interchangeably. It is also possible to install an alias (provided in most package managers) to map `docker` to `podman` if desired.
78+
## Quickstart
7579

76-
Podman, running as a standard user, is typically unable to bind to **low-numbered ports**. It is recommended to edit the `.env` file and uncomment the lines at top for AUTHNZ_PORT and AUTHNZ_HTTPS_PORT to remap those services to a higher port number. In the directions below, you would then use for example http://localhost:8084 and https://localhost:8443 instead of the default.
80+
`./quickstart.sh`
7781

78-
Note: If running on a system where **SELinux** is enabled, the system will not start if the appropriate security groups have not been defined. As an alternative, the `security_opt` sections can be commented out in the *-compose.yml files if required.
82+
The quickstart script will configure, build, and start the ANMS system for the first time. See comments in the script for additional details, including optional ENV variables to override default behavior.
7983

84+
To stop the system use `podman compose -f testenv-compose.yml -f docker-compose.yml down`.
8085

81-
## ANMS build and deploy
86+
To start the system in the future use `podman compose -f testenv-compose.yml up` and `podman compose up`.
8287

88+
## Manual Startup
8389
Choose the appropriate docker, podman or podman-compose commands in the directions below as appropriate for your system.
8490

85-
- Select appropriate profile(s) as desired.
86-
- If no profiles are set, a "light" deployment of the ANMS focused on browser-less API-only ANMS users.
87-
- For a full deployment: `export COMPOSE_PROFILES=full`
88-
- For a full deployment with additional developer tools: `export COMPOSE_PROFILES=full,dev`
91+
- Edit `.env` file as appropriately
92+
- Select appropriate profile(s) as desired.
93+
- Core ANMS services are always started.
94+
- The 'full' profile starts up all UI and related services.
95+
- The 'dev' profile adds development tools, such as adminer
96+
- Profiles can be set with COMPOSE_PROFILES in the .env file. The default includes full and dev profiles.
97+
- Adjust network ports as necessary to avoid any conflicts or permissions issues.
98+
- For rootless podman, the AUTHNZ_* ports must be changed to higher number ports to avoid permissions issues.
99+
- The corresponding lines can be uncommented in .env.
100+
- SELinux Security Labels Setup
101+
- If your system does not support security labels, no additional steps are needed.
102+
- If security labels are supported and you are unable to define them, they can be disabled for development purposes:
103+
- `cp docker-compose.no-security-override.yml docker-compose.override.yml`
89104
- Clone this repository recursively (`git clone --recursive https://github.com/NASA-AMMOS/anms.git`)
90105
- Setup Volume containing PKI configuration (certificate chains and private keys):
91106
- `./create_volume.sh ./puppet/modules/apl_test/files/anms/tls`
@@ -98,7 +113,6 @@ Choose the appropriate docker, podman or podman-compose commands in the directio
98113
- `docker compose -f testenv-compose.yml build`
99114
- `podman compose -f testenv-compose.yml build`
100115
- `podman-compose --podman-build-args='--format docker' -f testenv-compose.yml build`
101-
102116
- Start System using one of the following:
103117
- `docker compose -f docker-compose.yml up -d`
104118
- `podman compose -f docker-compose.yml up -d`

anms-core/anms/routes/adms/adm.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
AdmData = adm_data.AdmData
5757
DataModel = data_model_view.DataModel
5858

59-
ACCEPT_FILE_CONTENT_TYPE = "application/octet-stream"
59+
ACCEPT_FILE_CONTENT_TYPE = ["application/octet-stream","application/yang" ]
6060

6161

6262
class RequestError(BaseModel):
@@ -136,8 +136,10 @@ async def handle_adm(admset: ace.AdmSet, adm_file: ace.models.AdmModule, session
136136
if not replace:
137137
logger.info('Not replacing existing ADM name %s', adm_file.norm_name)
138138
return []
139+
data_rec = None
140+
async with get_async_session() as session:
141+
data_rec,_ = await AdmData.get(data_model_view.data_model_id,session)
139142

140-
data_rec = await AdmData.get(data_model_view.data_model_id)
141143
if data_rec:
142144
# Compare old and new contents
143145
logger.info("Checking existing ADM name %s", adm_file.norm_name)
@@ -194,7 +196,7 @@ async def update_adm(file: UploadFile, request: Request):
194196
message = ""
195197
error_details = [] # This is used to store the comparison details between the old adm and the new adm
196198
# Check if not application/json
197-
if file.content_type != ACCEPT_FILE_CONTENT_TYPE:
199+
if file.content_type not in ACCEPT_FILE_CONTENT_TYPE:
198200
message = f"Expect {ACCEPT_FILE_CONTENT_TYPE}. Received: {file.content_type}"
199201
status_code = status.HTTP_415_UNSUPPORTED_MEDIA_TYPE
200202
logger.error(message)
@@ -205,7 +207,7 @@ async def update_adm(file: UploadFile, request: Request):
205207
try:
206208
adm_file_contents = await file.read()
207209
try:
208-
adm_file = admset.load_from_data(io.BytesIO(adm_file_contents).getvalue(), del_dupe=False)
210+
adm_file = admset.load_from_data(io.StringIO(adm_file_contents.decode('utf-8')), del_dupe=False)
209211
except Exception as err:
210212
adm_file = None
211213
status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
@@ -214,19 +216,21 @@ async def update_adm(file: UploadFile, request: Request):
214216

215217
if adm_file:
216218
logger.info("Adm name: %s", adm_file.norm_name)
219+
data_rec = None
217220
# get data_model_id
218-
data_model_rec, error_message = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name )
219-
if error_message:
220-
raise Exception(error_message)
221-
222-
223-
data_rec, error_message = await AdmData.get(data_model_rec.data_model_id )
224-
if error_message:
225-
raise Exception(error_message)
221+
async with get_async_session() as session:
222+
data_model_rec = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name, session )
223+
if data_model_rec == None:
224+
logger.info("new ADM dont compare" )
225+
else:
226+
data_rec,_ = await AdmData.get(data_model_rec.data_model_id,session )
227+
if data_rec == None:
228+
logger.warning("ADM not in DB can't compare")
229+
226230
# Compare with existing adm
227231
if data_rec:
228232
# Compare old and new contents
229-
old_adm = admset.load_from_data(io.BytesIO(data_rec.data).getvalue(), del_dupe=False)
233+
old_adm = admset.load_from_data(io.StringIO(data_rec.data.decode('utf-8')), del_dupe=False)
230234
status_code = status.HTTP_200_OK
231235
if not comp.compare_adms(old_adm, adm_file):
232236
message = f"Updating existing adm {adm_file.norm_name}"
@@ -235,9 +239,10 @@ async def update_adm(file: UploadFile, request: Request):
235239
# reload adm_set
236240
admset.db_session().close()
237241
admset = ace.AdmSet(cache_dir=False)
238-
adm_file = admset.load_from_data(io.BytesIO(adm_file_contents), del_dupe=False)
242+
adm_file = admset.load_from_data(io.StringIO(adm_file_contents.decode('utf-8')), del_dupe=False)
239243
else: # if its the same nothing else to be done
240-
logger.info("Duplicate ADM add attempted")
244+
logger.warning("Duplicate ADM add attempted")
245+
message = "Duplicate ADM add attempted"
241246
response = JSONResponse(status_code=status_code,
242247
content={"message": message, "error_details": error_details})
243248
return response
@@ -277,7 +282,7 @@ async def update_adm(file: UploadFile, request: Request):
277282
try:
278283
async with get_async_session() as session:
279284
# get data_model_id
280-
285+
data_model_rec = await DataModel.get(adm_file.ns_model_enum, adm_file.ns_org_name, session )
281286
# Save the adm file of the new adm
282287
data = {"enumeration": data_model_rec.data_model_id, "data": adm_file_contents}
283288
response, error_message = await AdmData.add_data(data, session)

anms-core/integration_test/Dockerfile

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

anms-core/integration_test/docker-compose.yml

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,22 @@
2121
##
2222

2323
# Combine containers for anms-core and its test fixture
24-
version: '3.9'
24+
name: anms-integration-test
2525

2626
networks:
27-
default:
28-
name: ${DOCKER_CTR_PREFIX}anms
29-
driver_opts:
30-
com.docker.network.bridge.name: br-${DOCKER_CTR_PREFIX}anms
31-
com.docker.network.driver.mtu: 65535
27+
anms:
28+
external: true
29+
3230

3331
services:
3432
# External dependencies first
35-
postgres:
36-
hostname: postgres
37-
image: ${DOCKER_IMAGE_PREFIX}amp-sql:${DOCKER_IMAGE_TAG}
38-
environment:
39-
POSTGRES_USER: ${DB_USER}
40-
POSTGRES_PASSWORD: ${DB_PASSWORD}
41-
POSTGRES_DB: ${DB_NAME}
42-
mqtt-broker:
43-
hostname: mqtt-broker
44-
image: ${DOCKER_IMAGE_PREFIX}mqtt-broker:${DOCKER_IMAGE_TAG}
45-
transcoder:
46-
hostname: transcoder
47-
image: ${DOCKER_IMAGE_PREFIX}transcoder:${DOCKER_IMAGE_TAG}
48-
depends_on:
49-
mqtt-broker:
50-
condition: service_healthy
51-
52-
# anms-core built from *this* working copy (not prebuilt image)
53-
anms-core:
54-
hostname: anms-core
55-
build:
56-
context: ..
57-
volumes:
58-
- /var/run/docker.sock:/var/run/docker.sock
59-
depends_on:
60-
postgres:
61-
condition: service_healthy
62-
mqtt-broker:
63-
condition: service_healthy
64-
environment:
65-
DB_HOST: postgres
66-
DB_USER: ${DB_USER}
67-
DB_PASSWORD: ${DB_PASSWORD}
68-
DB_NAME: ${DB_NAME}
69-
7033
test-fixture:
7134
hostname: test-fixture
7235
build:
73-
context: .
74-
depends_on:
75-
anms-core:
76-
condition: service_healthy
36+
context: ../..
37+
dockerfile: anms.Containerfile
38+
target: anms-core-integration
39+
networks:
40+
- anms
41+
depends_on: {}
42+

anms-ui/server/components/adms.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
const requestTimeOut = 3000; //milliseconds
3939
const axios = require('axios');
4040
const FormData = require('form-data');
41-
const ACCEPTED_ADM_TYPE = 'application/json';
41+
const ACCEPTED_ADM_TYPE = 'application/octet-stream';
4242

4343
exports.getAll = async function (req, res, next) {
4444
try {
@@ -97,7 +97,7 @@
9797
exports.upload = async function (req, res, next) {
9898
const usersReqHeader = utils.createAuthenticationHeader(req);
9999
const file = req.file;
100-
100+
101101
if (!_.isNull(file) && file.mimetype != ACCEPTED_ADM_TYPE) {
102102
return res.status(415).json({"message": `Not support this ${file.mimetype}`});
103103
}
@@ -126,6 +126,7 @@
126126
});
127127
if (_.isNil(response) || _.isNil(response.data) || _.isNil(response.data.message)) {
128128
response.status = 500;
129+
console.error(response);
129130
response.data = {"message": "Internal Server Error"};
130131
}
131132
return res.status(response.status).json(response.data);

anms.Containerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ EXPOSE 5555/tcp
260260
HEALTHCHECK --start-period=10s --interval=60s --timeout=10s --retries=20 \
261261
CMD ["curl", "-sq", "-o/dev/null", "http://localhost:5555/hello"]
262262

263+
# for anms-core integration test
264+
FROM yarn-base AS anms-core-integration
265+
266+
# Install node+yarn from upstream
267+
RUN npm install --ignore-scripts -g newman
268+
269+
COPY anms-core/integration_test /root/
270+
WORKDIR /root
271+
CMD ["./run_test.sh"]
272+
263273

264274
# Build on more permissive CentOS image
265275
# Run on RHEL UBI image

0 commit comments

Comments
 (0)