Commit 53a40e23 authored by Aard's avatar Aard

[ssu] Add AppInstallMode and testcases, fixes JB#31869

parent 8c6d4bb9
......@@ -38,6 +38,9 @@ class Ssu: public QObject {
* ReleaseMode is defined to make a switch to allowing RnD and Release
* repositories on a device at the same time easy, if ever needed. Right
* now any mode where RndMode is not set is treated as ReleaseMode.
*
* If both UpdateMode and AppInstallMode are specified the device behaves
* like in AppInstallMode.
*/
enum DeviceMode {
DisableRepoManager = 0x1, ///< Disable automagic repository management
......@@ -45,6 +48,7 @@ class Ssu: public QObject {
ReleaseMode = 0x4, ///< Enable Release mode
LenientMode = 0x8, ///< Disable strict mode (i.e., keep unmanaged repositories)
UpdateMode = 0x10, ///< Do repo isolation and similar bits important for updating devices
AppInstallMode = 0x20 ///< Do repo isolation, but keep store repository enabled
};
Q_DECLARE_FLAGS(DeviceModeFlags, DeviceMode)
......
......@@ -28,10 +28,14 @@ SsuRepoManager::SsuRepoManager(): QObject() {
int SsuRepoManager::add(QString repo, QString repoUrl){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
// adding a repo is a noop when device is in update mode
// adding a repo is a noop when device is in update mode...
if ((ssuSettings->deviceMode() & Ssu::UpdateMode) == Ssu::UpdateMode)
return -1;
// ... or in AppInstallMode
if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode)
return -1;
if (repoUrl == ""){
// just enable a repository which has URL in repos.ini
QStringList enabledRepos;
......@@ -102,10 +106,14 @@ int SsuRepoManager::enable(QString repo){
int SsuRepoManager::remove(QString repo){
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
// removing a repo is a noop when device is in update mode
// removing a repo is a noop when device is in update mode...
if ((ssuSettings->deviceMode() & Ssu::UpdateMode) == Ssu::UpdateMode)
return -1;
// ... or AppInstallMode
if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode)
return -1;
if (ssuSettings->contains("repository-urls/" + repo))
ssuSettings->remove("repository-urls/" + repo);
......@@ -163,9 +171,16 @@ QStringList SsuRepoManager::repos(bool rnd, SsuDeviceInfo &deviceInfo, int filte
SsuCoreConfig *ssuSettings = SsuCoreConfig::instance();
bool updateMode = false;
bool appInstallMode = false;
if ((ssuSettings->deviceMode() & Ssu::UpdateMode) == Ssu::UpdateMode)
updateMode = true;
if ((ssuSettings->deviceMode() & Ssu::AppInstallMode) == Ssu::AppInstallMode){
updateMode = true;
appInstallMode = true;
}
if (filter == Ssu::NoFilter ||
filter == Ssu::UserFilter){
// user defined repositories, or ones overriding URLs for default ones
......@@ -187,6 +202,13 @@ QStringList SsuRepoManager::repos(bool rnd, SsuDeviceInfo &deviceInfo, int filte
// read user-enabled repositories from ssu.ini
if (ssuSettings->contains("enabled-repos") && !updateMode)
result.append(ssuSettings->value("enabled-repos").toStringList());
// if the store repository is enabled keep it enabled in AppInstallMode
if (ssuSettings->contains("enabled-repos") && appInstallMode){
// TODO store should not be hardcoded, but come via some store plugin
if (ssuSettings->value("enabled-repos").toStringList().contains("store"))
result.append("store");
}
}
if (filter == Ssu::NoFilter ||
......
......@@ -128,6 +128,8 @@ void SsuCli::optMode(QStringList opt){
modeList.append("LenientMode");
if ((deviceMode & Ssu::UpdateMode) == Ssu::UpdateMode)
modeList.append("UpdateMode");
if ((deviceMode & Ssu::AppInstallMode) == Ssu::AppInstallMode)
modeList.append("AppInstallMode");
qout << "Device mode is: " << ssu.deviceMode()
<< " (" << modeList.join(" | ") << ")" << endl;
......
......@@ -151,6 +151,31 @@ void RepoManagerTest::testCustomRepos(){
coreConfig->setDeviceMode(Ssu::RndMode | Ssu::UpdateMode, Ssu::Replace);
QCOMPARE(coreConfig->deviceMode(), Ssu::UpdateMode | Ssu::RndMode);
QVERIFY(rndRepos.toSet() == repoManager.repos().toSet());
// check appinstall mode
// custom repositories, apart from store, should be gone
customRepos.clear();
customRepos << "store";
// check release mode
coreConfig->setDeviceMode(Ssu::ReleaseMode | Ssu::AppInstallMode, Ssu::Replace);
QCOMPARE(coreConfig->deviceMode(), Ssu::ReleaseMode | Ssu::AppInstallMode);
set = releaseRepos.toSet().unite(repoManager.repos().toSet());
QCOMPARE(set.count(), 3);
QVERIFY(set == customRepos.toSet().unite(releaseRepos.toSet()));
// and rnd mode
coreConfig->setDeviceMode(Ssu::RndMode, Ssu::Add);
QCOMPARE(coreConfig->deviceMode(), Ssu::ReleaseMode | Ssu::AppInstallMode | Ssu::RndMode);
set = rndRepos.toSet().unite(repoManager.repos().toSet());
QCOMPARE(set.count(), 6);
QVERIFY(set == customRepos.toSet().unite(rndRepos.toSet()));
coreConfig->setDeviceMode(Ssu::RndMode | Ssu::AppInstallMode, Ssu::Replace);
QCOMPARE(coreConfig->deviceMode(), Ssu::AppInstallMode | Ssu::RndMode);
set = rndRepos.toSet().unite(repoManager.repos().toSet());
QCOMPARE(set.count(), 6);
QVERIFY(set == customRepos.toSet().unite(rndRepos.toSet()));
}
void RepoManagerTest::testRepos(){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment