Skip to content

Commit

Permalink
Add MQTT container log limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
atrovato committed Jan 14, 2023
1 parent 3d2ffc8 commit e0683a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
6 changes: 6 additions & 0 deletions server/services/mqtt/docker/eclipse-mosquitto-container.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"ExposedPorts": { "1883/tcp": {} },
"HostConfig": {
"Binds": ["/var/lib/gladysassistant/mosquitto:/mosquitto/config"],
"LogConfig": {
"Type": "json-file",
"Config": {
"max-size": "10m"
}
},
"PortBindings": {
"1883/tcp": [
{
Expand Down
2 changes: 1 addition & 1 deletion server/services/mqtt/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DEFAULT = {
IN_PROGRESS: 'IN_PROGRESS',
ERROR: 'ERROR',
},
MOSQUITTO_VERSION: '2',
MOSQUITTO_VERSION: '3',
};

module.exports = {
Expand Down
12 changes: 7 additions & 5 deletions server/services/mqtt/lib/updateContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const containerParams = require('../docker/eclipse-mosquitto-container.json');
async function updateContainer(configuration) {
logger.info('MQTT: checking for required changes...');

// Check for port listener option
// Check for update request
const { brokerContainerAvailable, mosquittoVersion } = configuration;
if (brokerContainerAvailable && !mosquittoVersion) {
logger.info('MQTT: update to mosquitto v2 required...');
if (brokerContainerAvailable && mosquittoVersion !== DEFAULT.MOSQUITTO_VERSION) {
logger.info(`MQTT: update #${DEFAULT.MOSQUITTO_VERSION} mosquitto container required...`);
const dockerContainers = await this.gladys.system.getContainers({
all: true,
filters: { name: [containerParams.name] },
});

// Remove non versionned container
// Remove old container
if (dockerContainers.length !== 0) {
const [container] = dockerContainers;
await this.gladys.system.removeContainer(container.id, { force: true });
Expand All @@ -36,7 +36,9 @@ async function updateContainer(configuration) {
DEFAULT.MOSQUITTO_VERSION,
this.serviceId,
);
logger.info('MQTT: update to mosquitto v2 done');
logger.info('MQTT: update mosquitto container done');
} else {
logger.info('MQTT: no container update required');
}

return configuration;
Expand Down
4 changes: 2 additions & 2 deletions server/test/services/mqtt/lib/getConfiguration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('mqttHandler.getConfiguration', () => {
.onCall(3)
.resolves(null)
.onCall(4)
.resolves('2')
.resolves('3')
.resolves('value'),
},
system: {
Expand All @@ -114,7 +114,7 @@ describe('mqttHandler.getConfiguration', () => {
dockerBased: true,
brokerContainerAvailable: true,
networkModeValid: false,
mosquittoVersion: '2',
mosquittoVersion: '3',
};
expect(config).to.deep.eq(expectedConfig);

Expand Down
18 changes: 11 additions & 7 deletions server/test/services/mqtt/lib/updateContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ describe('mqttHandler.updateContainer', function Describe() {
});

it('should updateContainer: already up-to-date', async () => {
const config = { brokerContainerAvailable: true, mosquittoVersion: '2' };
const config = {
brokerContainerAvailable: true,
mosquittoVersion: '3',
};

await mqttHandler.updateContainer(config);

Expand All @@ -71,17 +74,19 @@ describe('mqttHandler.updateContainer', function Describe() {
assert.calledOnce(gladys.system.restartContainer);
assert.calledOnce(installContainerMock.installContainer);

assert.calledOnce(gladys.variable.setValue);
assert.calledWith(
assert.calledOnceWithExactly(
gladys.variable.setValue,
CONFIGURATION.MQTT_MOSQUITTO_VERSION,
DEFAULT.MOSQUITTO_VERSION,
serviceId,
);
});

it('should updateContainer: MQTT container found', async () => {
const config = { brokerContainerAvailable: true };
it('should updateContainer: missing log limitation', async () => {
const config = {
brokerContainerAvailable: true,
mosquittoVersion: '2',
};
gladys.system.getContainers = fake.resolves([{ id: 'container' }]);

await mqttHandler.updateContainer(config);
Expand All @@ -95,8 +100,7 @@ describe('mqttHandler.updateContainer', function Describe() {

assert.calledOnce(installContainerMock.installContainer);

assert.calledOnce(gladys.variable.setValue);
assert.calledWith(
assert.calledOnceWithExactly(
gladys.variable.setValue,
CONFIGURATION.MQTT_MOSQUITTO_VERSION,
DEFAULT.MOSQUITTO_VERSION,
Expand Down

0 comments on commit e0683a7

Please sign in to comment.