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

init dashboard #118

Merged
merged 10 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ jobs:
- name: Install dependencies
run: cd udms && npm install
- name: Install angular command line
run: cd udms && npm install -g @angular/cli
run: cd udms && npm install -g @angular/cli firebase-tools
- name: Running lint
run: cd udms && ng lint
- name: Running unit tests
run: cd udms && ng test --browsers ChromeHeadless --code-coverage=true --watch=false
- name: Running e2e
run: cd udms && ng e2e
run: cd udms && npm run e2e

udmi:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions udms/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": {
"default": "bos-daq-testing",
"test": "bos-daq-testing"
}
}
3 changes: 3 additions & 0 deletions udms/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ testem.log
# System Files
.DS_Store
Thumbs.db

# Firebase emulator run logs
*-debug.log
2 changes: 2 additions & 0 deletions udms/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"src/assets"
],
"styles": [
"./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
"src/styles.scss"
],
"scripts": []
Expand Down Expand Up @@ -94,6 +95,7 @@
"src/assets"
],
"styles": [
"./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
"src/styles.scss"
],
"scripts": []
Expand Down
215 changes: 215 additions & 0 deletions udms/e2e/firestore/db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
{
"origin": [
{
"_id": "433cfd2c-33c2-491f-bb3f-f4fdb4fdcbab",
"type": "UDMS",
"system": [
{
"_id": "1614956054",
"controller": {
"state": "healthy",
"detail": "",
"change_count": 9,
"last_updated": 1614956054,
"last_changed": 1614956054
},
"dataplane": {
"state": "healthy",
"detail": "egress: us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 90,
"last_changed": 1614906054
},
"egress": {
"state": "healthy",
"detail": "us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 16,
"last_changed": 1614906054,
"active_root": "us-mtv-1685-t1sw1-1-2.n:1"
},
"processes": {
"state": "healthy",
"detail": "",
"change_count": 34,
"last_updated": 1614956054,
"last_changed": 1614906054
},
"state": "healthy",
"detail": "",
"change_count": 155,
"last_updated": 1614956054,
"last_changed": 1614956054
},
{
"_id": "1614961682",
"controller": {
"state": "damaged",
"detail": "CPN failures at: us-mtv-1685-t1sw1-1-2.n",
"change_count": 10,
"last_updated": 1614961682,
"last_changed": 1614956054
},
"dataplane": {
"state": "healthy",
"detail": "egress: us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 90,
"last_changed": 1614906054
},
"egress": {
"state": "healthy",
"detail": "us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 18,
"last_changed": 1614906054,
"active_root": "us-mtv-1685-t1sw1-1-2.n:1"
},
"processes": {
"state": "healthy",
"detail": "",
"change_count": 34,
"last_updated": 1614961682,
"last_changed": 1614906054
},
"state": "damaged",
"detail": "broken subsystems: cpn_state",
"change_count": 156,
"last_updated": 1614961682,
"last_changed": 1614956054
},
{
"_id": "1614961801",
"controller": {
"state": "damaged",
"detail": "CPN failures at: us-mtv-1685-t1sw1-1-2.n",
"change_count": 10,
"last_updated": 1614961801,
"last_changed": 1614956054
},
"dataplane": {
"state": "healthy",
"detail": "egress: us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 100,
"last_changed": 1614956054
},
"egress": {
"state": "healthy",
"detail": "us-mtv-1685-t1sw1-1-2.n:1",
"change_count": 25,
"last_changed": 1614956054,
"active_root": "us-mtv-1685-t1sw1-1-2.n:1"
},
"processes": {
"state": "healthy",
"detail": "",
"change_count": 34,
"last_updated": 1614961801,
"last_changed": 1614956054
},
"state": "damaged",
"detail": "broken subsystems: cpn_state",
"change_count": 156,
"last_updated": 1614961801,
"last_changed": 1614956054
}
],
"devices": [
{
"_id": "dc:1d:f2:e8:78:c6",
"attributes": {
"ip": "10.20.0.101",
"mac": "dc:1d:f2:e8:78:c6",
"port": 1,
"vlan": 270,
"role": ""
},
"tests": [
{
"_id": "5eac611f",
"config": {
"site_description": "Default Configuration",
"switch_setup": {
"of_dpid": 2,
"uplink_port": 7
},
"settle_sec": 5
},
"run_info": {
"started": 1614950000
},
"modules": [
{
"_id": "ping",
"report_path": "bucket/somefile",
"state": "done",
"last_updated": 1614950054,
"started": 1614950004,
"config": {
"enabled": true
},
"exception": null
},
{
"_id": "nmap",
"report_path": "bucket/somefile",
"state": "done",
"last_updated": 1614950054,
"started": 1614950104,
"config": {
"enabled": true
},
"exception": null
}
]
},
{
"_id": "5eac6122",
"config": {
"site_description": "Default Configuration",
"switch_setup": {
"of_dpid": 2,
"uplink_port": 7
},
"settle_sec": 5
},
"run_info": {
"started": 1614950204
},
"modules": [
{
"_id": "ping",
"report_path": "bucket/somefile",
"state": "done",
"last_updated": 1614950054,
"started": 1614950204,
"config": {
"enabled": true
},
"exception": null
},
{
"_id": "nmap",
"report_path": "bucket/somefile",
"state": "done",
"last_updated": 1614950204,
"started": 1614950301,
"config": {
"enabled": true
},
"exception": null
}
]
}
]
},
{
"_id": "dc:1d:f2:e8:78:c9",
"attributes": {
"ip": "10.20.0.102",
"mac": "dc:1d:f2:e8:78:c9",
"port": 1,
"vlan": 270,
"role": ""
}
}
]
}
]
}
89 changes: 89 additions & 0 deletions udms/e2e/firestore/import_db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
process.env.FIREBASE_AUTH_EMULATOR_HOST = "localhost:9099";
const firebase = require("firebase-admin");
const fs = require('fs');
const path = require('path');
const assert = require('assert').strict;

const firebaseConfig = {
// Any id will work as long as UI is also connecting using the same id
// Default projects are specified in project root/.firebasrc
projectId: "bos-daq-testing",
};
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();

function isDoc(data) {
return !!data._id;
}

function isCollection(data) {
return data instanceof Array;
}

function isTimestamp(data) {
return typeof data === 'number' && data > 1000000000;
}

function isMap(data) {
return Object.prototype.toString.call(data) === "[object Object]";
}

function formatMap(doc) {
let formattedMap = {};
Object.keys(doc).forEach((key) => {
let value = doc[key];
if (isTimestamp(value)) {
formattedMap[key] = new Date(value);
} else if (isMap(value)){
formattedMap[key] = formatMap(value);
} else {
formattedMap[key] = value;
}
});
return formattedMap;
}

async function importDoc(ref, doc) {
assert.ok(isDoc(doc));
const formattedDoc = {};
const collections = [];
Object.keys(doc).forEach((key) => {
let value = doc[key];
if (isTimestamp(value)) {
formattedDoc[key] = new Date(value);
} else if (isCollection(value)) {
collections.push(key);
} else if (isMap(value)) {
formattedDoc[key] = formatMap(value)
} else {
formattedDoc[key] = value;
}
});
await ref.doc(doc._id).set(formattedDoc);
await Promise.all(collections.map((name) => {
return importCollection(ref.doc(doc._id), name, doc[name]);
}));
}

async function importCollection(ref, name, data) {
const collection = ref.collection(name);
data.forEach(async (doc) => {
await importDoc(collection, doc);
});
}

async function clearDB() {
const query = await db.collection("origin").get();
await Promise.all(query.docs.map((doc) => {
return doc.ref.delete();
}));
}

async function importDB() {
const dbFile = fs.readFileSync(path.resolve(__dirname, "db.json"));
const db_json = JSON.parse(dbFile);
await importCollection(db, "origin", db_json.origin);
}

clearDB().then(importDB);
15 changes: 13 additions & 2 deletions udms/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ describe('workspace-project App', () => {
page = new AppPage();
});

it('should display welcome message', async () => {
it('should display title', async () => {
await page.navigateTo();
expect(await page.getTitleText()).toEqual('udms app is running!');
expect(await page.getTitleText()).toEqual('UDMS');
});

it('should be redirected to signin page', async () => {
await page.navigateTo('/dashboard');
expect(await page.getCurrentUrl()).toEqual('login');
});

it('should be able to navigate to dashboard when signed in', async () => {
await page.signIn();
await page.navigateTo('/dashboard');
expect(await page.getCurrentUrl()).toEqual('dashboard');
});

afterEach(async () => {
Expand Down
Loading