Skip to content

Commit

Permalink
Merge pull request #1833 from balena-io/overall-status-balena-vpn-con…
Browse files Browse the repository at this point in the history
…trol

device.overall_status: Use the BALENA_SUPERVISOR_VPN_CONTROL config var as well
  • Loading branch information
joshbwlng authored Nov 5, 2024
2 parents 5db86ec + 6fb3058 commit 9654175
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 27 deletions.
18 changes: 16 additions & 2 deletions src/features/devices/models/device-additions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ const isVpnEnabled: NotEqualsNode = [
['ReferencedField', 'device', 'id'],
],
[
'Equals',
'In',
['ReferencedField', 'device config variable', 'name'],
['EmbeddedText', 'BALENA_SUPERVISOR_VPN_CONTROL'],
['EmbeddedText', 'RESIN_SUPERVISOR_VPN_CONTROL'],
],
],
],
// Prefer the `BALENA_` version when both are set, as the Supervisor does.
[
'OrderBy',
['ASC', ['ReferencedField', 'device config variable', 'name']],
],
['Limit', ['Number', 1]],
],
[
'SelectQuery',
Expand All @@ -96,12 +103,19 @@ const isVpnEnabled: NotEqualsNode = [
['ReferencedField', 'device', 'belongs to-application'],
],
[
'Equals',
'In',
['ReferencedField', 'application config variable', 'name'],
['EmbeddedText', 'BALENA_SUPERVISOR_VPN_CONTROL'],
['EmbeddedText', 'RESIN_SUPERVISOR_VPN_CONTROL'],
],
],
],
// Prefer the `BALENA_` version when both are set, as the Supervisor does.
[
'OrderBy',
['ASC', ['ReferencedField', 'application config variable', 'name']],
],
['Limit', ['Number', 1]],
],
// Adding a COALESCE default value to avoid the need for NotEquals to compare 'false' with NULL
['EmbeddedText', 'not set'],
Expand Down
56 changes: 44 additions & 12 deletions test/24_device_additions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ export default () => {
fx.devices.deviceVpnOffHeartbeatTimeout;
ctx.deviceVpnOffHeartbeatOffline =
fx.devices.deviceVpnOffHeartbeatOffline;
ctx.deviceVpnOffHeartbeatTimeoutVPNDisabled =
fx.devices.deviceVpnOffHeartbeatTimeoutVPNDisabled;
ctx.deviceWithDeviceConfigVPNDisabled =
fx.devices.deviceWithDeviceConfigVPNDisabled;
ctx.deviceWithApplicationConfigVPNDisabled =
fx.devices.deviceWithApplicationConfigVPNDisabled;
ctx.deviceWithDeviceConfigVPNEnabled =
fx.devices.deviceWithDeviceConfigVPNEnabled;
ctx.deviceVpnOffHeartbeatTimeoutResinVpnDisabled =
fx.devices.deviceVpnOffHeartbeatTimeoutResinVpnDisabled;
ctx.deviceWithDeviceConfigResinVpnDisabled =
fx.devices.deviceWithDeviceConfigResinVpnDisabled;
ctx.deviceWithDeviceConfigBalenaVpnDisabled =
fx.devices.deviceWithDeviceConfigBalenaVpnDisabled;
ctx.deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled =
fx.devices.deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled;
ctx.deviceWithApplicationConfigResinVpnDisabled =
fx.devices.deviceWithApplicationConfigResinVpnDisabled;
ctx.deviceWithDeviceConfigResinVpnEnabled =
fx.devices.deviceWithDeviceConfigResinVpnEnabled;
ctx.deviceWithDeviceConfigBalenaVpnEnabled =
fx.devices.deviceWithDeviceConfigBalenaVpnEnabled;
ctx.deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled =
fx.devices.deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled;
ctx.deviceInPreProvisioningState =
fx.devices.deviceInPreProvisioningState;
ctx.deviceInPostProvisioningState =
Expand Down Expand Up @@ -202,25 +210,49 @@ export default () => {
itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'reduced-functionality' : 'idle',
'when the heartbeat is Timeout and and RESIN_SUPERVISOR_VPN_CONTROL is false',
'deviceVpnOffHeartbeatTimeoutVPNDisabled',
'deviceVpnOffHeartbeatTimeoutResinVpnDisabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'operational' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and RESIN_SUPERVISOR_VPN_CONTROL is false',
'deviceWithDeviceConfigVPNDisabled',
'deviceWithDeviceConfigResinVpnDisabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'operational' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and BALENA_SUPERVISOR_VPN_CONTROL is false',
'deviceWithDeviceConfigBalenaVpnDisabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'operational' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and BALENA_SUPERVISOR_VPN_CONTROL is false and RESIN_SUPERVISOR_VPN_CONTROL is true',
'deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'reduced-functionality' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and RESIN_SUPERVISOR_VPN_CONTROL is true',
'deviceWithDeviceConfigVPNEnabled',
'deviceWithDeviceConfigResinVpnEnabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'reduced-functionality' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and BALENA_SUPERVISOR_VPN_CONTROL is true',
'deviceWithDeviceConfigBalenaVpnEnabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'reduced-functionality' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and BALENA_SUPERVISOR_VPN_CONTROL is true and RESIN_SUPERVISOR_VPN_CONTROL is false',
'deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled',
);

itShouldHaveOverallStatus(
versions.gt(version, 'v6') ? 'operational' : 'idle',
'should have an ${OVERALL_STATUS} overall_status when the heartbeat is Online and RESIN_SUPERVISOR_VPN_CONTROL is false in application config variables',
'deviceWithApplicationConfigVPNDisabled',
'deviceWithApplicationConfigResinVpnDisabled',
);

itShouldHaveOverallStatus(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{
"variable1": {
"user": "admin",
"application": "app2",
"application": "appResinVpnDisabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variable2": {
"user": "admin",
"application": "appBalenaVpnDisabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variable3": {
"user": "admin",
"application": "appBalenaVpnDisabledResinVpnDisabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "true"
},
"variable4": {
"user": "admin",
"application": "appBalenaVpnDisabledResinVpnDisabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "false"
}
}
18 changes: 16 additions & 2 deletions test/fixtures/24-device-additions/applications.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
"commit": "deadbeef",
"should_track_latest_release": 1
},
"app2": {
"appResinVpnDisabled": {
"user": "admin",
"app_name": "test_config_variables",
"app_name": "test_resin_config_variables",
"device_type": "raspberry-pi",
"commit": "deadbeef",
"should_track_latest_release": 1
},
"appBalenaVpnDisabled": {
"user": "admin",
"app_name": "test_balena_config_variables",
"device_type": "raspberry-pi",
"commit": "deadbeef",
"should_track_latest_release": 1
},
"appBalenaVpnDisabledResinVpnDisabled": {
"user": "admin",
"app_name": "test_resin_balena_config_variables",
"device_type": "raspberry-pi",
"commit": "deadbeef",
"should_track_latest_release": 1
Expand Down
46 changes: 41 additions & 5 deletions test/fixtures/24-device-additions/device_config_variables.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
{
"variable1": {
"variableDeviceWithVpnDisabled1": {
"user": "admin",
"device": "deviceWithDeviceConfigVPNDisabled",
"device": "deviceWithDeviceConfigResinVpnDisabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variable2": {
"variableDeviceWithVpnDisabled2": {
"user": "admin",
"device": "deviceWithDeviceConfigVPNEnabled",
"device": "deviceWithDeviceConfigBalenaVpnDisabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variableDeviceWithVpnDisabled3": {
"user": "admin",
"device": "deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "true"
},
"variableDeviceWithVpnDisabled4": {
"user": "admin",
"device": "deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variableDeviceWithVpnEnabled1": {
"user": "admin",
"device": "deviceWithDeviceConfigResinVpnEnabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "true"
},
"variableDeviceWithVpnEnabled2": {
"user": "admin",
"device": "deviceWithDeviceConfigBalenaVpnEnabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "true"
},
"variableDeviceWithVpnEnabled3": {
"user": "admin",
"device": "deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "false"
},
"variableDeviceWithVpnEnabled4": {
"user": "admin",
"device": "deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled",
"name": "BALENA_SUPERVISOR_VPN_CONTROL",
"value": "true"
},
"variable3": {
"user": "admin",
"device": "deviceVpnOffHeartbeatTimeoutVPNDisabled",
"device": "deviceVpnOffHeartbeatTimeoutResinVpnDisabled",
"name": "RESIN_SUPERVISOR_VPN_CONTROL",
"value": "false"
}
Expand Down
60 changes: 55 additions & 5 deletions test/fixtures/24-device-additions/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceVpnOffHeartbeatTimeoutVPNDisabled": {
"deviceVpnOffHeartbeatTimeoutResinVpnDisabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
"api_heartbeat_state": "timeout",
"os_variant": "prod",
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceVpnOffHeartbeatTimeoutBalenaVpnDisabledResinVpnDisabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
Expand All @@ -99,7 +109,7 @@
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithDeviceConfigVPNDisabled": {
"deviceWithDeviceConfigResinVpnDisabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
Expand All @@ -109,8 +119,48 @@
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithApplicationConfigVPNDisabled": {
"belongs_to__application": "app2",
"deviceWithDeviceConfigBalenaVpnDisabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
"api_heartbeat_state": "online",
"os_variant": "prod",
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithDeviceConfigBalenaVpnDisabledResinVpnEnabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
"api_heartbeat_state": "online",
"os_variant": "prod",
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithApplicationConfigResinVpnDisabled": {
"belongs_to__application": "appResinVpnDisabled",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
"api_heartbeat_state": "online",
"os_variant": "prod",
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithDeviceConfigResinVpnEnabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
"api_heartbeat_state": "online",
"os_variant": "prod",
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithDeviceConfigBalenaVpnEnabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
"is_online": false,
Expand All @@ -119,7 +169,7 @@
"os_version": "Resin OS 2.11.0+rev1",
"supervisor_version": "6.4.2"
},
"deviceWithDeviceConfigVPNEnabled": {
"deviceWithDeviceConfigBalenaVpnEnabledResinVpnDisabled": {
"belongs_to__application": "app1",
"device_type": "raspberry-pi",
"belongs_to__user": "admin",
Expand Down

0 comments on commit 9654175

Please sign in to comment.