Skip to content

Commit e456aa0

Browse files
shwstpprdavidjumani
authored andcommitted
script fixes
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 28b1a2b commit e456aa0

File tree

5 files changed

+55
-9
lines changed

5 files changed

+55
-9
lines changed

python/lib/cloudutils/networkConfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def isBridgeSupported():
8787
if os.path.exists("/proc/sys/net/bridge"):
8888
return True
8989

90-
return bash("modprobe -b bridge").isSucess()
90+
return bash("modprobe -b bridge").isSuccess()
9191

9292
@staticmethod
9393
def isNetworkDev(devName):

python/lib/cloudutils/serviceConfig.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
Unknown = 0
2828
CentOS6 = 1
2929
CentOS7 = 2
30-
Ubuntu = 3
31-
RHEL6 = 4
32-
RHEL7 = 5
30+
CentOS8 = 3
31+
Ubuntu = 4
32+
RHEL6 = 5
33+
RHEL7 = 6
34+
RHEL8 = 7
3335
distro = None
3436

3537
#=================== DISTRIBUTION DETECTION =================
@@ -39,12 +41,16 @@
3941
distro = CentOS6
4042
elif version.find("CentOS Linux release 7") != -1:
4143
distro = CentOS7
44+
elif version.find("CentOS Linux release 8") != -1:
45+
distro = CentOS8
4246
elif os.path.exists("/etc/redhat-release"):
4347
version = open("/etc/redhat-release").readline()
4448
if version.find("Red Hat Enterprise Linux Server release 6") != -1:
4549
distro = RHEL6
4650
elif version.find("Red Hat Enterprise Linux Server 7") != -1:
4751
distro = RHEL7
52+
elif version.find("Red Hat Enterprise Linux Server 8") != -1:
53+
distro = RHEL8
4854
elif os.path.exists("/etc/lsb-release") and "Ubuntu" in open("/etc/lsb-release").read(-1): distro = Ubuntu
4955
else: distro = Unknown
5056
#=================== DISTRIBUTION DETECTION =================
@@ -343,7 +349,7 @@ def config(self):
343349
cfo.addEntry("NOZEROCONF", "yes")
344350
cfo.save()
345351

346-
if not bash("service network restart").isSuccess():
352+
if not bash("systemctl restart NetworkManager.service").isSuccess():
347353
raise CloudInternalException("Can't restart network")
348354

349355
self.syscfg.env.nics.append(self.brName)

python/lib/cloudutils/syscfg.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
from .utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu,serviceOpsRedhat7
17+
from .utilities import Distribution, serviceOpsRedhat,serviceOpsUbuntu,serviceOpsRedhat7,serviceOpsRedhat8
1818
from .serviceConfig import *
1919
class sysConfigFactory:
2020
@staticmethod
@@ -43,6 +43,8 @@ def getAgent(glbEnv):
4343
return sysConfigRedhat5(glbEnv)
4444
elif distribution == "RHEL7":
4545
return sysConfigRedhat7(glbEnv)
46+
elif distribution == "RHEL8":
47+
return sysConfigRedhat8(glbEnv)
4648
else:
4749
print("Can't find the distribution version")
4850
return sysConfig()
@@ -147,6 +149,11 @@ def __init__(self, env):
147149
self.svo = serviceOpsRedhat7()
148150
super(sysConfigAgentRedhat7Base, self).__init__(env)
149151

152+
class sysConfigAgentRedhat8Base(sysConfigAgent):
153+
def __init__(self, env):
154+
self.svo = serviceOpsRedhat8()
155+
super(sysConfigAgentRedhat8Base, self).__init__(env)
156+
150157
class sysConfigAgentUbuntu(sysConfigAgent):
151158
def __init__(self, glbEnv):
152159
super(sysConfigAgentUbuntu, self).__init__(glbEnv)
@@ -193,6 +200,17 @@ def __init__(self, glbEnv):
193200
nfsConfig(self),
194201
cloudAgentConfig(self)]
195202

203+
#it covers RHEL8
204+
class sysConfigRedhat8(sysConfigAgentRedhat8Base):
205+
def __init__(self, glbEnv):
206+
super(sysConfigRedhat8, self).__init__(glbEnv)
207+
self.services = [securityPolicyConfigRedhat(self),
208+
networkConfigRedhat(self),
209+
libvirtConfigRedhat(self),
210+
firewallConfigAgent(self),
211+
nfsConfig(self),
212+
cloudAgentConfig(self)]
213+
196214
class sysConfigServer(sysConfig):
197215
def check(self):
198216
if os.geteuid() != 0:

python/lib/cloudutils/test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python3
2+
3+
from .utilities import bash
4+
import logging
5+
6+
cmd = bash("route -n|awk \'/^0.0.0.0/ {print $2,$8}\'")
7+
if not cmd.isSuccess():
8+
logging.debug("Failed to get default route")
9+
raise CloudRuntimeException("Failed to get default route")
10+
11+
result = cmd.getStdout().split(" ")

python/lib/cloudutils/utilities.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ def isSuccess(self):
6060
return self.success
6161

6262
def getStdout(self):
63-
return self.stdout.strip("\n")
63+
return self.stdout.decode('utf-8').strip('\n')
6464

6565
def getLines(self):
66-
return self.stdout.split("\n")
66+
return self.stdout.decode('utf-8').strip('\n')
6767

6868
def getStderr(self):
69-
return self.stderr.strip("\n")
69+
return self.stderr.decode('utf-8').strip('\n')
7070

7171
def getErrMsg(self):
7272
if self.isSuccess():
@@ -114,6 +114,8 @@ def __init__(self):
114114
self.distro = "RHEL6"
115115
elif version.find("Red Hat Enterprise Linux Server release 7") != -1 or version.find("Scientific Linux release 7") != -1 or version.find("CentOS Linux release 7") != -1 or version.find("CentOS release 7.") != -1:
116116
self.distro = "RHEL7"
117+
elif version.find("Red Hat Enterprise Linux Server release 8") != -1 or version.find("Scientific Linux release 8") != -1 or version.find("CentOS Linux release 8") != -1 or version.find("CentOS release 8.") != -1:
118+
self.distro = "RHEL8"
117119
elif version.find("CentOS") != -1:
118120
self.distro = "CentOS"
119121
else:
@@ -222,6 +224,15 @@ def isServiceRunning(self, servicename):
222224
except:
223225
return False
224226

227+
class serviceOpsRedhat8(serviceOps):
228+
def isServiceRunning(self, servicename):
229+
try:
230+
o = bash("systemctl is-active " + servicename)
231+
textout = o.getStdout()
232+
return "inactive" not in textout and "failed" not in textout
233+
except:
234+
return False
235+
225236
def stopService(self, servicename,force=False):
226237
if self.isServiceRunning(servicename) or force:
227238
return bash("systemctl stop " + servicename).isSuccess()

0 commit comments

Comments
 (0)