|
@@ -33,11 +33,16 @@ from resource_management.libraries.functions.format import format
|
|
|
from resource_management.core.environment import Environment
|
|
|
from resource_management.core.shell import checked_call
|
|
|
from resource_management.core import sudo
|
|
|
+from resource_management.core.logger import Logger
|
|
|
import re
|
|
|
|
|
|
REPO_TEMPLATE_FOLDER = 'data'
|
|
|
|
|
|
+
|
|
|
class RhelSuseRepositoryProvider(Provider):
|
|
|
+
|
|
|
+ update_cmd = ['zypper', 'clean', '--all']
|
|
|
+
|
|
|
def action_create(self):
|
|
|
with Environment.get_instance_copy() as env:
|
|
|
repo_file_name = self.resource.repo_file_name
|
|
@@ -45,12 +50,23 @@ class RhelSuseRepositoryProvider(Provider):
|
|
|
new_content = InlineTemplate(self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name,
|
|
|
base_url=self.resource.base_url, mirror_list=self.resource.mirror_list)
|
|
|
repo_file_path = format("{repo_dir}/{repo_file_name}.repo")
|
|
|
- if self.resource.append_to_file and os.path.isfile(repo_file_path):
|
|
|
- content = sudo.read_file(repo_file_path) + '\n' + new_content.get_content()
|
|
|
- else:
|
|
|
+
|
|
|
+ if os.path.isfile(repo_file_path):
|
|
|
+ existing_content_str = sudo.read_file(repo_file_path)
|
|
|
+ new_content_str = new_content.get_content()
|
|
|
+ if existing_content_str != new_content_str and OSCheck.is_suse_family():
|
|
|
+ # We need to reset package manager's cache when we replace base urls
|
|
|
+ # at existing repo. That is a case at least under SLES
|
|
|
+ Logger.info("Flushing package manager cache since repo file content is about to change")
|
|
|
+ checked_call(self.update_cmd, sudo=True)
|
|
|
+ if self.resource.append_to_file:
|
|
|
+ content = existing_content_str + '\n' + new_content_str
|
|
|
+ else:
|
|
|
+ content = new_content_str
|
|
|
+ else: # If repo file does not exist yet
|
|
|
content = new_content
|
|
|
-
|
|
|
- File(repo_file_path,
|
|
|
+
|
|
|
+ File(repo_file_path,
|
|
|
content=content
|
|
|
)
|
|
|
|
|
@@ -60,7 +76,7 @@ class RhelSuseRepositoryProvider(Provider):
|
|
|
repo_dir = get_repo_dir()
|
|
|
|
|
|
File(format("{repo_dir}/{repo_file_name}.repo"),
|
|
|
- action = "delete")
|
|
|
+ action="delete")
|
|
|
|
|
|
|
|
|
def get_repo_dir():
|
|
@@ -69,6 +85,7 @@ def get_repo_dir():
|
|
|
elif OSCheck.is_suse_family():
|
|
|
return '/etc/zypp/repos.d'
|
|
|
|
|
|
+
|
|
|
class UbuntuRepositoryProvider(Provider):
|
|
|
package_type = "deb"
|
|
|
repo_dir = "/etc/apt/sources.list.d"
|
|
@@ -80,8 +97,8 @@ class UbuntuRepositoryProvider(Provider):
|
|
|
with Environment.get_instance_copy() as env:
|
|
|
with tempfile.NamedTemporaryFile() as tmpf:
|
|
|
with tempfile.NamedTemporaryFile() as old_repo_tmpf:
|
|
|
- repo_file_name = format("{repo_file_name}.list",repo_file_name = self.resource.repo_file_name)
|
|
|
- repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir = self.repo_dir)
|
|
|
+ repo_file_name = format("{repo_file_name}.list",repo_file_name=self.resource.repo_file_name)
|
|
|
+ repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
|
|
|
|
|
|
new_content = InlineTemplate(self.resource.repo_template, package_type=self.package_type,
|
|
|
base_url=self.resource.base_url,
|
|
@@ -120,8 +137,8 @@ class UbuntuRepositoryProvider(Provider):
|
|
|
|
|
|
def action_remove(self):
|
|
|
with Environment.get_instance_copy() as env:
|
|
|
- repo_file_name = format("{repo_file_name}.list",repo_file_name = self.resource.repo_file_name)
|
|
|
- repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir = self.repo_dir)
|
|
|
+ repo_file_name = format("{repo_file_name}.list", repo_file_name=self.resource.repo_file_name)
|
|
|
+ repo_file_path = format("{repo_dir}/{repo_file_name}", repo_dir=self.repo_dir)
|
|
|
|
|
|
if os.path.isfile(repo_file_path):
|
|
|
File(repo_file_path,
|