Skip to content

Commit 7aa762f

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/177-ghcr_container_publishing
2 parents d8c1743 + 8a541ed commit 7aa762f

File tree

7 files changed

+86
-117
lines changed

7 files changed

+86
-117
lines changed

.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+

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

deps/test-ion-configs/mgr.rc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ION Configuration File for Node N1, ipn:1
1+
# ION Configuration File for Node N1, ipn:1, hostname manager
22
## begin ionadmin
33
1 1 ''
44
s
@@ -12,12 +12,13 @@ m horizon +0
1212
## begin bpadmin
1313
1
1414
e 1
15+
w 1
1516
a scheme ipn 'ipnfw' 'ipnadminep'
1617
a endpoint ipn:1.0 x
1718
a endpoint ipn:1.1 x
1819
a endpoint ipn:1.4 x
19-
a endpoint ipn:1.6 x
20-
a endpoint ipn:1.7 x
20+
a endpoint ipn:1.6 q
21+
a endpoint ipn:1.7 q
2122

2223

2324
# Protocols
@@ -28,19 +29,17 @@ a protocol tcp 1400 100
2829
a induct udp 0.0.0.0:4556 udpcli
2930

3031
# Outducts
31-
a outduct udp 127.0.0.1 udpclo
32-
a outduct udp ION-AGENT2:4556 udpclo
33-
a outduct udp ION-AGENT3:4556 udpclo
34-
32+
a outduct udp 10.5.0.101:4556 udpclo
33+
a outduct udp 10.5.0.102:4556 udpclo
34+
a outduct udp 10.5.0.103:4556 udpclo
3535

3636
s
3737
## end bpadmin
3838

3939
## begin ipnadmin
40-
a plan 1 udp/127.0.0.1
41-
a plan 2 udp/ION-AGENT2:4556
42-
a plan 3 udp/ION-AGENT3:4556
43-
40+
a plan 1 udp/10.5.0.101:4556
41+
a plan 2 udp/10.5.0.102:4556
42+
a plan 3 udp/10.5.0.103:4556
4443

4544
## end ipnadmin
4645

0 commit comments

Comments
 (0)