Commit Graph

58 Commits

Author SHA1 Message Date
Felipe Lalanne
f1cd3d367c Cleanup unused methods and dependencies on db ids 2022-03-22 19:28:43 -03:00
Felipe Lalanne
5c5483dd3d Rename networks to <appUuid>_<networkName>
This is required as we are phasing out app ids and we need to be able to
get app uuid from the current state of the network. The app-id now
exists as a container in new networks

This commit will restart containers as it needs to recreate the network.
2022-03-22 19:08:03 -03:00
Felipe Lalanne
ccae1f7cb8 Rename aplication manager getStatus as getLegacyState
With the move to v3 target state and the move forward to remove
database ids from the supervisor, we want to ensure the ids are only
used for legacy support (such as within the API). This change renames
the method and sets it as deprecated
2022-03-22 19:08:02 -03:00
Felipe Lalanne
f1bd4b8d9b Use tags to track supervised images in docker
The image manager module now uses tags instead of docker IDs as the main
way to identify docker images on the engine. That is, if the target
state image has a name `imageName:tag@digest`, the supervisor will always use
the given `imageName` and `tag` (which may be empty) to tag the image on
the engine after fetching. This PR also adds checkups to ensure
consistency is maintained between the database and the engine.

Using tags allows to simplify query and removal operations, since now
removing the image now means removing tags matching the image name.

Before this change the supervisor relied only on information in the
supervisor database, and used that to remove images by docker ID. However, the docker
id is not a reliable identifier, since images retain the same id between
releases or between services in the same release.

List of squashed commits
- Remove custom type NormalizedImageInfo
- Remove dependency on docker-toolbelt
- Use tags to traack supervised images in docker
- Ensure tag removal occurs in sequence
- Only save database image after download confirmed

Relates-to: #1616 #1579
Change-type: patch
2021-07-26 09:52:25 -04:00
Felipe Lalanne
357d1baf61 Fix db-helper module for tests
The previous module was using `rewire` to get the knex instance from the
db module but that was leading to issues when running tests using `test:fast`.
This provides a fix for the test module that just removes the destroy
call entirely (it turns out it is not necessary).

Change-type: patch
2021-07-08 14:43:13 -04:00
Felipe Lalanne
e04e64763f Improve testing for supervisor composition modules
This PR cleans up testing for supervisor compose modules. It also fixes broken
tests for application manager and removes a lot of dependencies for those tests
on DB and other unnecessary mocks. There are probably a lot of cases that tests
are missing but this should make writing new tests a lot easier.

This PR also creates a new mock dockerode (mockerode) module that should make it
easier to test operations that interact with the engine. All references
to the old mock-dockerode have not yet been removed but that should come
soon in another PR

List of squashed commits:
- Add tests for network create/remove
- Move compose service tests to test/src/compose and reorganize test descriptions
- Add support for image creation to mockerode
- Add additional tests for compose volumes
- Update mockerode so unimplemented fake methods throw. This is to ensure
  tests using mockerode fail if an unimplemented method is used
- Update tests for volume-manager with mockerode
- Update tests for compose/images
- Simplify tests using mockerode
- Clean up compose/app tests
- Create application manager tests

Change-type: minor
2021-07-05 17:50:52 -04:00
Pagan Gazzard
ee4d919fca Improve target state typings
Change-type: patch
2021-06-08 13:45:44 +01:00
Christina Wang
dcd863eed8
Add toggleable SUPERVISOR_HARDWARE_METRICS config
On devices with bandwidth sensitivity, this config var
disables sending system information such as memory
usage or cpu temp as current state.

Closes: #1645
Change-type: minor
Signed-off-by: Christina Wang <christina@balena.io>
2021-05-13 13:59:07 +09:00
Christina Wang
62375c907f
Upgrade mocha to v8, use mocha fixtures for chai plugins
Remove chai-events and add explicit chai devDependency

Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2021-05-12 17:10:57 +09:00
Christina Wang
4a2ac557ef
Remove mz, mkdirp, body-parser dependencies
'mz' can be safely replaced with fs.promises
and util.promisify for faster native methods.
'mkdirp' after Node v8 uses native fs.mkdir, thus
is redundant. 'body-parser' is deprecated and
contained within express v4.x.

Closes: #1567
Change-type: patch
Signed-off-by: Christina Wang <christina@balena.io>
2021-04-28 07:20:15 +09:00
Felipe Lalanne
c70aedf044 Fix mock dockerode module
Tests using the mock `testWithData` method were not restoring the dockerode
prototype to the default values, making some tests behave differently
when run individually that when run with the suite.

This commit fixes the `testWithData` method and some malfunctioning v1
API tests because of the change. It doesn't fix all the tests
2021-04-27 13:00:56 -04:00
Miguel Casqueira
183ea88a2a Infer legacy Volumes that do not have the supervised label
Change-type: patch
Closes: #1604
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-03-15 19:46:53 -04:00
Christina Wang
b3b1d47b34
Complete /v1/device/host-config unit tests, modify PATCH route
Change-type: minor
Signed-off-by: Christina Wang <christina@balena.io>
2021-02-18 12:25:44 +09:00
Miguel Casqueira
ba1c857c4f Cancel pending apply target after /v1/update request
Closes: #1530
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2021-01-20 22:21:14 -05:00
Felipe Lalanne
4cdf26f82f Improve supervisor API behavior when locks are set
This PR adds the following

* Supervisor v1 API application actions now return HTTP status code 423 when locks
  are preventing the action to be performed. Previously this resulted in a
  503 error
* Supervisor API v2 service actions now returns HTTP status code 423 when locks are
  preventing the action to be performed. Previously, this resulted in an
  exception logged by the supervisor and the API query timing out
* Supervisor API `/v2/applications/:appId/start-service` now does not
  check for a lock. Lock handling in v2 actions is now performed by each
  step executor
* `/v1/apps/:appId/start` now queries the target state and uses that
  information to execute the start step (as v2 does). Previously start
  resulted in `cannot get appId from undefined`
* Extra tests for API methods

Change-type: patch
Connects-to: #1523
Signed-off-by: Felipe Lalanne <felipe@balena.io>
2020-12-14 10:43:41 -03:00
Miguel Casqueira
8b37df492b Patched /v1/restart exception
Change-type: patch
Closes: #1509
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Miguel Casqueira
7a4473f65b Added test case for /v1/restart API
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-30 15:42:49 -05:00
Cameron Diver
f08316dc57 Allow storing commits against their appIds
This paves the way for running multiple applications and storing
information related to the application against the application itself. A
couple of hacks have been added to v1 and v2 endpoints to maintain
compatability but these should eventually be removed with the addition
of a v3 api.

Change-type: minor
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-11-10 10:50:08 +00:00
Miguel Casqueira
cd0d53c39d Add more test coverage for compose/images
Closes: #1492
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-11-03 13:08:41 -05:00
Rich Bayliss
c08de8701e api: Implement scoped Supervisor API keys
Each service, when requesting access to the Supervisor API, will
now get an individual key which can be scoped to specific resources.
In this iteration the default scope will be to the application that
the service belongs to.

We also have a `global` scope which is used by the cloud API when in
managed mode.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-09-17 11:25:56 +00:00
Rich Bayliss
96c68166a1
application-manager: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 11:23:36 +01:00
Rich Bayliss
e3864915bc
device-state: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Rich Bayliss
d50f7791e1
api-binder: Convert to a singleton
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-09-14 09:31:12 +01:00
Pagan Gazzard
379730a9e1 Update typed-error to 3.x
Update typed-error from 2.0.0 to 3.2.1

Change-type: patch
2020-08-19 10:07:54 +01:00
Rich Bayliss
5aecd94e24
bug: Firewall not blocking supervisor access from outside the device
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-08-12 13:43:33 +01:00
Pagan Gazzard
511cbbe74e Update pinejs-client-request and make use of a named key
Update pinejs-client-request from 7.0.0 to 7.1.0

Change-type: patch
2020-08-03 09:27:11 +00:00
Nitish Agarwal
11cac2dd69 Fixes #1299 v1 start/stop endpoint issue with service access.
Change-Type: patch
Signed-off-by: Nitish Agarwal <1592163+nitishagar@users.noreply.github.com>
2020-07-31 23:08:50 +05:30
Matthew McGinn
15c57a86b4
fix up "atleast" -> "at least"
Change-type: patch
Signed-off-by: Matthew McGinn <matthew@balena.io>
2020-07-29 11:55:22 -04:00
Rich Bayliss
6ef3bd2362
docker-utils: Test network gateway determination logic
Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-22 13:17:16 +01:00
Rich Bayliss
898c7e71da
bug: Fix unhandled promise rejection
When invoking iptables-restore it can fail. This wasn't handled
and this makes sure that it fails gracefully.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-13 13:05:12 +01:00
Rich Bayliss
28c5a44e71
firewall: Add Host Firewall functionality
Controlled by BALENA_HOST_FIREWALL_MODE, the firewall can
either be 'on' or 'off'.

- In the 'off' state, all traffic is allowed.
- In the 'on' state, only traffic for the core services provided
  by Balena is allowed.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-07-01 18:43:08 +01:00
Rich Bayliss
1b91ef3405
state: Report device MAC address to the API
When reporting device information, send the MAC address of any
interfaces on the system. Also expose in the Supervisor API at
the route GET /v1/device.

Change-type: patch
Signed-off-by: Rich Bayliss <rich@balena.io>
2020-06-22 10:41:06 +01:00
Cameron Diver
0e8d92e08a Make service-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Cameron Diver
adaad786af Make volume-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Cameron Diver
8fc97b9de8 Make network-manager module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-17 14:56:57 +00:00
Akis Kesoglou
1dccbaecd8 Use API v6
See: https://github.com/balena-io/open-balena/issues/80
Change-type: minor
2020-06-15 13:57:32 +03:00
Cameron Diver
b31d5007fb Move database app processing out to its own module
This is part of the work to make the application-manager module much
less monolithic, in preperation for system apps and more generally
multi-app.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-11 11:55:11 +01:00
Cameron Diver
2b3dc2fbce Make images module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-10 11:29:28 +01:00
Cameron Diver
651e48b1bd Make logger module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-08 17:19:20 +01:00
Cameron Diver
389e14ec6b Make the event-tracker module a singleton
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-08 10:13:33 +01:00
Cameron Diver
ff4a31a0e6 Make the config module a singleton
Change-type: patch
Co-authored-by: Pagan Gazzard <page@balena.io>
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-06-02 14:29:05 +01:00
Miguel Casqueira
f494178b2b Added test coverage for GET /v1/healthy
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-29 16:14:15 -04:00
Cameron Diver
1d7381327e Make the db module a singleton
We were treating the database class as a singleton, but still having to pass
around the db instance. Now we can simply require the db module and have
access to the database handle.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-29 15:02:38 +01:00
Cameron Diver
eaaa9c257e check for 409 status code, rather than string matching uuid conflicts
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2020-05-21 14:57:26 -04:00
Miguel Casqueira
db7c27037c Improved handling of invalid appId in V2 state endpoint
Closes: #1294
Change-type: patch
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-19 10:53:19 -04:00
Pagan Gazzard
758f3caa48 Update to @balena/lint 5.x
Change-type: patch
2020-05-15 12:08:42 +01:00
Miguel Casqueira
8295858b32 Added endpoint to check if VPN is connected
Change-type: minor
Signed-off-by: Miguel Casqueira <miguel@balena.io>
2020-05-11 21:21:44 -04:00
Theodor Gherzan
d6adfa189f
Do not polute test output with unncessarry stack trace
Signed-off-by: Theodor Gherzan <theodor@balena.io>
2019-11-19 09:48:56 +00:00
Cameron Diver
b5a427f2b9
Convert some coffeescript tests to typescript
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-10-30 10:58:32 +00:00
Cameron Diver
050c10dbb0 Add volume tests and fix test fixture setup for applications
Change-type: patch
Signed-off-by: Cameron Diver <cameron@balena.io>
2019-07-10 14:25:46 +01:00