Skip to content

Commit

Permalink
Merge pull request #1835 from uyuni-project/pillar_migration_on_minio…
Browse files Browse the repository at this point in the history
…nid_change

Migrate pillar and formula data on minion id change
  • Loading branch information
aaannz authored Feb 6, 2020
2 parents dc7ed0b + 465732b commit 7a330e1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015--2019 SUSE LLC
* Copyright (c) 2015--2020 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand Down Expand Up @@ -225,15 +225,20 @@ public boolean checkIfMinionAlreadyRegistered(String minionId,
if (!minionId.equals(oldMinionId)) {
LOG.warn("Minion '" + oldMinionId + "' already registered, updating " +
"profile to '" + minionId + "' [" + machineId + "]");

registeredMinion.setName(minionId);
registeredMinion.setMinionId(minionId);
ServerFactory.save(registeredMinion);
SystemManager.addHistoryEvent(registeredMinion, "Duplicate Machine ID", "Minion '" +
oldMinionId + "' has been updated to '" + minionId + "'");

if (!minionId.equals(oldMinionId)) {
SALT_SERVICE.deleteKey(oldMinionId);
}
SaltStateGeneratorService.INSTANCE.generatePillar(registeredMinion);
SaltStateGeneratorService.INSTANCE.removePillar(oldMinionId);

migrateMinionFormula(minionId, Optional.of(oldMinionId));

SALT_SERVICE.deleteKey(oldMinionId);

SystemManager.addHistoryEvent(registeredMinion, "Duplicate Minion ID", "Minion '" +
oldMinionId + "' has been updated to '" + minionId + "'");
}

// Saltboot treatment
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 SUSE LLC
* Copyright (c) 2016--2020 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand Down Expand Up @@ -186,7 +186,7 @@ public void generatePillar(MinionServer minion, boolean refreshAccessTokens,
try {
Files.createDirectories(pillarDataPath);
Path filePath = pillarDataPath.resolve(
getServerPillarFileName(minion)
getServerPillarFileName(minion.getMinionId())
);
com.suse.manager.webui.utils.SaltStateGenerator saltStateGenerator =
new com.suse.manager.webui.utils.SaltStateGenerator(filePath.toFile());
Expand Down Expand Up @@ -368,9 +368,9 @@ public static String getChannelHost(Server server) {
}
}

private String getServerPillarFileName(MinionServer minion) {
private String getServerPillarFileName(String minionId) {
return PILLAR_DATA_FILE_PREFIX + "_" +
minion.getMinionId() + "." +
minionId + "." +
PILLAR_DATA_FILE_EXT;
}

Expand All @@ -380,13 +380,21 @@ private String getImagePillarFileName(OSImageInspectSlsResult.Bundle bundle) {
}

/**
* Remove the corresponding pillar data if the server is a minion.
* Remove the corresponding pillar data of minion server
* @param minion the minion server
*/
public void removePillar(MinionServer minion) {
LOG.debug("Removing pillar file for minion: " + minion.getMinionId());
removePillar(minion.getMinionId());
}

/**
* Remove the corresponding pillar data by minionId
* @param minionId the server minionId
*/
public void removePillar(String minionId) {
LOG.debug("Removing pillar file for minion: " + minionId);
Path filePath = pillarDataPath.resolve(
getServerPillarFileName(minion));
getServerPillarFileName(minionId));
try {
Files.deleteIfExists(filePath);
}
Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Migrate pillar and formula data on minion id change (bsc#1161755)
- Remove auditlog-keeper
- Exclude base products from PAYG (Pay-As-You-Go) instances when doing subscription matching
- call saltutil.sync_all before calling highstate (bsc#1152673)
Expand Down

0 comments on commit 7a330e1

Please sign in to comment.