/[smeserver]/cdrom.image/sme9/updates/upgrade.py
ViewVC logotype

Annotation of /cdrom.image/sme9/updates/upgrade.py

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download) (as text)
Mon Mar 11 18:03:05 2013 UTC (11 years, 7 months ago) by slords
Branch: MAIN
Content type: text/x-python
New sme9 tree

1 slords 1.1 #
2     # upgrade.py - Existing install probe and upgrade procedure
3     #
4     # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Red Hat, Inc.
5     # All rights reserved.
6     #
7     # This program is free software; you can redistribute it and/or modify
8     # it under the terms of the GNU General Public License as published by
9     # the Free Software Foundation; either version 2 of the License, or
10     # (at your option) any later version.
11     #
12     # This program is distributed in the hope that it will be useful,
13     # but WITHOUT ANY WARRANTY; without even the implied warranty of
14     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     # GNU General Public License for more details.
16     #
17     # You should have received a copy of the GNU General Public License
18     # along with this program. If not, see <http://www.gnu.org/licenses/>.
19     #
20     # Author(s): Matt Wilson <msw@redhat.com>
21     #
22    
23     import isys
24     import os
25     import iutil
26     import time
27     import sys
28     import os.path
29     import shutil
30     import string
31     import selinux
32     from flags import flags
33     from constants import *
34     from product import productName
35     from storage import findExistingRootDevices, getReleaseString
36     from storage import mountExistingSystem
37     from storage.formats import getFormat
38    
39     import gettext
40     _ = lambda x: gettext.ldgettext("anaconda", x)
41    
42     import rpm
43    
44     import logging
45     log = logging.getLogger("anaconda")
46    
47     def queryUpgradeContinue(anaconda):
48     if anaconda.dir == DISPATCH_FORWARD:
49     return
50    
51     rc = anaconda.intf.messageWindow(_("Proceed with upgrade?"),
52     _("The file systems of the Linux installation "
53     "you have chosen to upgrade have already been "
54     "mounted. You cannot go back past this point. "
55     "\n\n") +
56     _("Would you like to continue with the upgrade?"),
57     type="custom", custom_icon=["error","error"],
58     custom_buttons=[_("_Exit installer"), _("_Continue")])
59     if rc == 0:
60     sys.exit(0)
61     return DISPATCH_FORWARD
62    
63     def setUpgradeRoot(anaconda):
64     anaconda.id.upgradeRoot = []
65     root_device = None
66     # kickstart can pass device as device name or uuid. No quotes allowed.
67     if anaconda.isKickstart and anaconda.id.ksdata.upgrade.root_device is not None:
68     root_device = anaconda.id.ksdata.upgrade.root_device
69     for (dev, label) in anaconda.id.rootParts:
70     if ((root_device is not None) and
71     (root_device == dev.name or root_device == "UUID=%s" % dev.format.uuid)):
72     anaconda.id.upgradeRoot.insert(0, (dev,label))
73     else:
74     anaconda.id.upgradeRoot.append((dev,label))
75    
76     def findRootParts(anaconda):
77     if anaconda.dir == DISPATCH_BACK:
78     return
79     if anaconda.id.rootParts is None:
80     anaconda.id.rootParts = findExistingRoots(anaconda,
81     flags.cmdline.has_key("upgradeany"))
82    
83     setUpgradeRoot(anaconda)
84    
85     if anaconda.id.rootParts is not None and len(anaconda.id.rootParts) > 0:
86     anaconda.dispatch.skipStep("findinstall", skip = 0)
87     if productName.find("SME Server") == -1:
88     anaconda.dispatch.skipStep("installtype", skip = 1)
89     else:
90     anaconda.dispatch.skipStep("findinstall", skip = 1)
91     anaconda.dispatch.skipStep("installtype", skip = 0)
92    
93     def findExistingRoots(anaconda, upgradeany=False):
94     rootparts = findExistingRootDevices(anaconda, upgradeany=upgradeany)
95     return rootparts
96    
97     def bindMountDevDirectory(instPath):
98     getFormat("bind",
99     device="/dev",
100     mountpoint="/dev",
101     exists=True).mount(chroot=instPath)
102    
103     # returns None if no filesystem exist to migrate
104     def upgradeMigrateFind(anaconda):
105     migents = anaconda.id.storage.migratableDevices
106     if not migents or len(migents) < 1:
107     anaconda.dispatch.skipStep("upgrademigratefs")
108     else:
109     anaconda.dispatch.skipStep("upgrademigratefs", skip = 0)
110    
111    
112     # returns None if no more swap is needed
113     def upgradeSwapSuggestion(anaconda):
114     # mem is in kb -- round it up to the nearest 4Mb
115     mem = iutil.memInstalled()
116     rem = mem % 16384
117     if rem:
118     mem = mem + (16384 - rem)
119     mem = mem / 1024
120    
121     anaconda.dispatch.skipStep("addswap", 0)
122    
123     # don't do this if we have more then 250 MB
124     if mem > 250:
125     anaconda.dispatch.skipStep("addswap", 1)
126     return
127    
128     swap = iutil.swapAmount() / 1024
129    
130     # if we have twice as much swap as ram and at least 192 megs
131     # total, we're safe
132     if (swap >= (mem * 1.5)) and (swap + mem >= 192):
133     anaconda.dispatch.skipStep("addswap", 1)
134     return
135    
136     # if our total is 512 megs or more, we should be safe
137     if (swap + mem >= 512):
138     anaconda.dispatch.skipStep("addswap", 1)
139     return
140    
141     fsList = []
142    
143     for device in anaconda.id.storage.fsset.devices:
144     if not device.format:
145     continue
146     if device.format.mountable and device.format.linuxNative:
147     if not device.format.status:
148     continue
149     space = isys.pathSpaceAvailable(anaconda.rootPath + device.format.mountpoint)
150     if space > 16:
151     info = (device, space)
152     fsList.append(info)
153    
154     suggestion = mem * 2 - swap
155     if (swap + mem + suggestion) < 192:
156     suggestion = 192 - (swap + mem)
157     if suggestion < 32:
158     suggestion = 32
159     suggSize = 0
160     suggMnt = None
161     for (device, size) in fsList:
162     if (size > suggSize) and (size > (suggestion + 100)):
163     suggDev = device
164    
165     anaconda.id.upgradeSwapInfo = (fsList, suggestion, suggDev)
166    
167     # XXX handle going backwards
168     def upgradeMountFilesystems(anaconda):
169     # mount everything and turn on swap
170    
171     try:
172     mountExistingSystem(anaconda,
173     anaconda.id.upgradeRoot[0],
174     allowDirty = 0)
175     except ValueError as e:
176     log.error("Error mounting filesystem: %s" % e)
177     anaconda.intf.messageWindow(_("Mount failed"),
178     _("The following error occurred when mounting the file "
179     "systems listed in /etc/fstab. Please fix this problem "
180     "and try to upgrade again.\n%s" % e))
181     sys.exit(0)
182     except IndexError as e:
183     # The upgrade root is search earlier but we give the message here.
184     log.debug("No upgrade root was found.")
185     if anaconda.isKickstart and anaconda.id.ksdata.upgrade.upgrade:
186     anaconda.intf.messageWindow(_("Upgrade root not found"),
187     _("The root for the previously installed system was not "
188     "found."), type="custom",
189     custom_icon="info",
190     custom_buttons=[_("Exit installer")])
191     sys.exit(0)
192     else:
193     rc = anaconda.intf.messageWindow(_("Upgrade root not found"),
194     _("The root for the previously installed system was not "
195     "found. You can exit installer or backtrack to choose "
196     "installation instead of upgrade."),
197     type="custom",
198     custom_buttons = [ _("_Back"),
199     _("_Exit installer") ],
200     custom_icon="question")
201     if rc == 0:
202     return DISPATCH_BACK
203     elif rc == 1:
204     sys.exit(0)
205    
206     checkLinks = ( '/etc', '/var', '/var/lib', '/var/lib/rpm',
207     '/boot', '/tmp', '/var/tmp', '/root',
208     '/bin/sh', '/usr/tmp')
209     badLinks = []
210     for n in checkLinks:
211     if not os.path.islink(anaconda.rootPath + n): continue
212     l = os.readlink(anaconda.rootPath + n)
213     if l[0] == '/':
214     badLinks.append(n)
215    
216     if badLinks:
217     message = _("The following files are absolute symbolic "
218     "links, which we do not support during an "
219     "upgrade. Please change them to relative "
220     "symbolic links and restart the upgrade.\n\n")
221     for n in badLinks:
222     message = message + '\t' + n + '\n'
223     anaconda.intf.messageWindow(_("Absolute Symlinks"), message)
224     sys.exit(0)
225    
226     # fix for 80446
227     badLinks = []
228     mustBeLinks = ( '/usr/tmp', )
229     for n in mustBeLinks:
230     if not os.path.islink(anaconda.rootPath + n):
231     badLinks.append(n)
232    
233     if badLinks:
234     message = _("The following are directories which should instead "
235     "be symbolic links, which will cause problems with the "
236     "upgrade. Please return them to their original state "
237     "as symbolic links and restart the upgrade.\n\n")
238     for n in badLinks:
239     message = message + '\t' + n + '\n'
240     anaconda.intf.messageWindow(_("Invalid Directories"), message)
241     sys.exit(0)
242    
243     anaconda.id.storage.turnOnSwap(upgrading=True)
244     anaconda.id.storage.mkDevRoot()
245    
246     # Move /etc/rpm/platform out of the way.
247     if os.path.exists(anaconda.rootPath + "/etc/rpm/platform"):
248     shutil.move(anaconda.rootPath + "/etc/rpm/platform",
249     anaconda.rootPath + "/etc/rpm/platform.rpmsave")
250    
251     # if they've been booting with selinux disabled, then we should
252     # disable it during the install as well (#242510)
253     try:
254     if os.path.exists(anaconda.rootPath + "/.autorelabel"):
255     ctx = selinux.getfilecon(anaconda.rootPath + "/.autorelabel")[1]
256     if not ctx or ctx == "unlabeled":
257     flags.selinux = False
258     log.info("Disabled SELinux for upgrade based on /.autorelabel")
259     except Exception, e:
260     log.warning("error checking selinux state: %s" %(e,))
261    
262     def setSteps(anaconda):
263     dispatch = anaconda.dispatch
264     dispatch.setStepList(
265     "language",
266     "keyboard",
267     "welcome",
268     "filtertype",
269     "filter",
270     "installtype",
271     "storageinit",
272     "findrootparts",
273     "findinstall",
274     "upgrademount",
275     "upgrademigfind",
276     "upgrademigratefs",
277     "enablefilesystems",
278     "upgradecontinue",
279     "reposetup",
280     "upgbootloader",
281     "checkdeps",
282     "dependencies",
283     "confirmupgrade",
284     "postselection",
285     "reipl",
286     "install",
287     "preinstallconfig",
288     "installpackages",
289     "postinstallconfig",
290     "instbootloader",
291     "dopostaction",
292     "methodcomplete",
293     "postscripts",
294     "copylogs",
295     "complete"
296     )
297    
298     if not iutil.isX86() and not iutil.isS390():
299     dispatch.skipStep("bootloader")
300     dispatch.skipStep("upgbootloader")
301    
302     dispatch.skipStep("cleardiskssel", permanent=1)

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed