Browse code

Use pkg_info.json to find rpm files of a package.

Change-Id: I5e935dc97fc05a2858b46c1c03c2e6634aab89fe
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/1838
Reviewed-by: Divya Thaluru <dthaluru@vmware.com>
Tested-by: gerrit-photon <photon-checkins@vmware.com>

xiaolin-vmware authored on 2016/12/14 03:14:49
Showing 4 changed files
... ...
@@ -84,6 +84,7 @@ micro-iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES_MICRO)
84 84
                 -r $(PHOTON_STAGE)/RPMS \
85 85
                 -p $(PHOTON_GENERATED_DATA_DIR)/$(MICRO_PACKAGE_LIST_FILE) \
86 86
                 -o $(PHOTON_STAGE)/common/data \
87
+                -d $(PHOTON_STAGE)/pkg_info.json \
87 88
                 -s $(PHOTON_DATA_DIR) \
88 89
                 -f > \
89 90
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
... ...
@@ -118,6 +119,7 @@ minimal-iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES_MINIMAL)
118 118
                 -r $(PHOTON_STAGE)/RPMS \
119 119
                 -p $(PHOTON_GENERATED_DATA_DIR)/$(MINIMAL_PACKAGE_LIST_FILE) \
120 120
                 -o $(PHOTON_STAGE)/common/data \
121
+                -d $(PHOTON_STAGE)/pkg_info.json \
121 122
                 -s $(PHOTON_DATA_DIR) \
122 123
                 -f > \
123 124
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
... ...
@@ -146,6 +148,7 @@ live-iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES_MINIMAL) minimal-iso
146 146
                 -r $(PHOTON_STAGE)/RPMS \
147 147
                 -p $(PHOTON_GENERATED_DATA_DIR)/build_install_options_livecd.json \
148 148
                 -o $(PHOTON_STAGE)/common/data \
149
+                -d $(PHOTON_STAGE)/pkg_info.json \
149 150
                 -s $(PHOTON_DATA_DIR) \
150 151
                 -f > \
151 152
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
... ...
@@ -178,6 +181,7 @@ iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES) ostree-repo
178 178
                 -x $(PHOTON_STAGE)/SRPMS \
179 179
                 -p $(PHOTON_GENERATED_DATA_DIR)/$(FULL_PACKAGE_LIST_FILE) \
180 180
                 -o $(PHOTON_STAGE)/common/data \
181
+                -d $(PHOTON_STAGE)/pkg_info.json \
181 182
                 -s $(PHOTON_DATA_DIR) \
182 183
                 -f > \
183 184
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
... ...
@@ -193,6 +197,7 @@ custom-iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES)
193 193
                 -x $(PHOTON_STAGE)/SRPMS \
194 194
                 -p $(PHOTON_GENERATED_DATA_DIR)/build_install_options_custom.json \
195 195
                 -o $(PHOTON_STAGE)/common/data \
196
+                -d $(PHOTON_STAGE)/pkg_info.json \
196 197
                 -s $(PHOTON_DATA_DIR) \
197 198
                 -f > \
198 199
                 $(PHOTON_LOGS_DIR)/installer.log 2>&1
... ...
@@ -208,6 +213,7 @@ src-iso: check-tools $(PHOTON_STAGE) $(PHOTON_PACKAGES)
208 208
                 -x $(PHOTON_STAGE)/SRPMS \
209 209
                 -p $(PHOTON_GENERATED_DATA_DIR)/$(FULL_PACKAGE_LIST_FILE) \
210 210
                 -o $(PHOTON_STAGE)/common/data \
211
+                -d $(PHOTON_STAGE)/pkg_info.json \
211 212
                 -s $(PHOTON_DATA_DIR) \
212 213
                 -f > \
213 214
                 $(PHOTON_LOGS_DIR)/sourceiso-installer.log 2>&1
... ...
@@ -118,14 +118,14 @@ fi
118 118
 mkdir -p ${BUILDROOT}/mnt/photon-root/photon-chroot
119 119
 rm -rf ${BUILDROOT}/RPMS
120 120
 
121
+run_command " echo ${RPMS_PATH}" "echo ${RPMS_PATH}" "${LOGFILE}"
121 122
 #cp -r ${RPMS_PATH} ${WORKINGDIR}/
122 123
 (
123 124
 cd ${RPMS_PATH}
124 125
 mkdir ${WORKINGDIR}/RPMS
125 126
 for rpm_name in $RPM_LIST; do
126
-    FILENAME="`find . -name "$rpm_name-[0-9]*" -or -name "$rpm_name-[a-z][0-9]*" -or -name "$rpm_name-debuginfo*" -type f`"
127
-    if [ -n "$FILENAME" ]; then
128
-        cp --parent $FILENAME ${WORKINGDIR}/RPMS/;
127
+    if [ -f "$rpm_name" ]; then
128
+        cp --parent $rpm_name ${WORKINGDIR}/RPMS/;
129 129
     fi
130 130
 done
131 131
 )
132 132
deleted file mode 100755
... ...
@@ -1,43 +0,0 @@
1
-#!/bin/bash
2
-#################################################
3
-#       Title:  mk-src-iso                      #
4
-#        Date:  2016-02-19                      #
5
-#     Version:  1.0                             #
6
-#      Author:  dthaluru@vmware.com             #
7
-#     Options:                                  #
8
-#################################################
9
-#   Overview
10
-#       Generates a photon source iso
11
-#   End
12
-#
13
-
14
-set +x                 # disable hashall
15
-PRGNAME=${0##*/}        # script name minus the path
16
-source config.inc       #   configuration parameters
17
-LOGFILE=/var/log/"${PRGNAME}-${LOGFILE}"    #   set log file name
18
-
19
-# Grab the name of the iso file 
20
-if [ $# -lt 2 ]
21
-then
22
-    echo "Usage : " $0 " <output-iso-with-path>  <srpms-path> <pkg-list-path>"
23
-    exit 1
24
-fi
25
-ISO_OUTPUT_NAME=$1
26
-SRPMS_PATH=$2
27
-SRPM_LIST=$3
28
-
29
-WORKINGDIR=${BUILDROOT}
30
-rm -r ${WORKINGDIR}/*
31
-(
32
-cd ${SRPMS_PATH}
33
-mkdir ${WORKINGDIR}/SRPMS
34
-for srpm_name in $SRPM_LIST; do
35
-    FILENAME="`find . -name "$srpm_name-[0-9]*" -type f`"
36
-    if [ -n "$FILENAME" ]; then
37
-        cp --parent $FILENAME ${WORKINGDIR}/SRPMS/;
38
-    fi
39
-done
40
-)
41
-
42
-mkisofs -r -o $ISO_OUTPUT_NAME $WORKINGDIR/
43
-
... ...
@@ -87,7 +87,13 @@ def create_vmdk_and_partition(config, vmdk_path):
87 87
 
88 88
     return partitions_data, count == 2
89 89
 
90
-def create_rpm_list_to_copy_in_iso(build_install_option, output_data_path):
90
+def get_file_name_with_last_folder(filename):
91
+    basename = os.path.basename(filename)
92
+    dirname = os.path.dirname(filename)
93
+    lastfolder = os.path.basename(dirname)
94
+    name = os.path.join(lastfolder, basename)
95
+    return name
96
+def create_pkg_list_to_copy_to_iso(build_install_option, output_data_path):
91 97
     json_wrapper_option_list = JsonWrapper(build_install_option)
92 98
     option_list_json = json_wrapper_option_list.read()
93 99
     options_sorted = option_list_json.items()
... ...
@@ -100,6 +106,31 @@ def create_rpm_list_to_copy_in_iso(build_install_option, output_data_path):
100 100
             packages = packages + package_list_json["packages"]
101 101
     return packages
102 102
 
103
+    #copy_flags 1: add the rpm file for the package
104
+    #           2: add debuginfo rpm file for the package.
105
+    #           4: add src rpm file for the package
106
+def create_rpm_list_to_be_copied_to_iso(pkg_to_rpm_map_file, build_install_option, copy_flags, output_data_path):
107
+    packages = []
108
+    if build_install_option is None:
109
+        packages = []
110
+    else:
111
+        packages = create_pkg_list_to_copy_to_iso(build_install_option, output_data_path)
112
+
113
+    rpm_list = []
114
+    json_pkg_to_rpm_map = JsonWrapper(pkg_to_rpm_map_file)
115
+    pkg_to_rpm_map = json_pkg_to_rpm_map.read()
116
+    for k in pkg_to_rpm_map:
117
+        if build_install_option is None or k in packages:
118
+            if not pkg_to_rpm_map[k]['rpm'] is None and bool(copy_flags & 1):
119
+                filename = pkg_to_rpm_map[k]['rpm']
120
+                rpm_list.append(get_file_name_with_last_folder(filename))
121
+            if not pkg_to_rpm_map[k]['debugrpm'] is None and bool(copy_flags & 2):
122
+                filename = pkg_to_rpm_map[k]['debugrpm']
123
+                rpm_list.append(get_file_name_with_last_folder(filename))
124
+            if not pkg_to_rpm_map[k]['sourcerpm'] is None and bool(copy_flags & 4):
125
+                rpm_list.append(pkg_to_rpm_map[k]['sourcerpm'])
126
+    return rpm_list
127
+
103 128
 def create_additional_file_list_to_copy_in_iso(base_path, build_install_option):
104 129
     json_wrapper_option_list = JsonWrapper(build_install_option)
105 130
     option_list_json = json_wrapper_option_list.read()
... ...
@@ -121,6 +152,22 @@ def get_live_cd_status_string(build_install_option):
121 121
                 return "true"
122 122
     return "false"
123 123
 
124
+def make_src_iso(working_directory, src_iso_path, rpm_list):
125
+    if os.path.isdir(working_directory):
126
+        process = subprocess.Popen(['rm', '-rf', working_directory])
127
+        retval = process.wait()
128
+    process = subprocess.Popen(['mkdir', '-p', os.path.join(working_directory, "SRPMS")])
129
+    retval = process.wait()
130
+    for aaa in rpm_list:
131
+        if os.path.isfile(aaa):
132
+            process = subprocess.Popen(['cp', aaa, os.path.join(working_directory, "SRPMS")])
133
+            retval = process.wait()
134
+    process = subprocess.Popen(['mkisofs', '-r', '-o', src_iso_path, working_directory])
135
+    retval = process.wait()
136
+    process = subprocess.Popen(['rm', '-rf', options.working_directory])
137
+    retval = process.wait()
138
+
139
+
124 140
 if __name__ == '__main__':
125 141
     usage = "Usage: %prog [options] <config file> <tools path>"
126 142
     parser = OptionParser(usage)
... ...
@@ -138,120 +185,108 @@ if __name__ == '__main__':
138 138
     parser.add_option("-m", "--stage-path", dest="stage_path", default="../stage")
139 139
     parser.add_option("-c", "--dracut-configuration", dest="dracut_configuration_file", default="../common/data/dracut_configuration.json")
140 140
     parser.add_option("-s", "--json-data-path", dest="json_data_path", default="../stage/common/data/")
141
+    parser.add_option("-d", "--pkg-to_rpm-map-file", dest="pkg_to_rpm_map_file", default="../stage/pkg_info.json")
141 142
 
142 143
     (options,  args) = parser.parse_args()
143
-    if options.iso_path or options.src_iso_path:
144
-        # Check the arguments
145
-        if (len(args)) != 0:
146
-            parser.error("Incorrect arguments")
147
-        config = {}
148
-        config['iso_system'] = True
149
-        config['vmdk_install'] = False
150
-
151
-    elif options.vmdk_path:
152
-        # Check the arguments
153
-        if (len(args)) != 1:
154
-            parser.error("Incorrect arguments")
155
-
156
-        # Read the conf file
157
-        config = (JsonWrapper(args[0])).read()
158
-        config['disk'], success = create_vmdk_and_partition(config, options.vmdk_path)
159
-        if not success:
160
-            print "Unexpected failure, please check the logs"
161
-            sys.exit(1)
162
-
163
-        config['initrd_dir'] = "/boot"
164
-
165
-        config['iso_system'] = False
166
-        config['vmdk_install'] = True
167
-
168
-    else:
169
-        # Check the arguments
170
-        if (len(args)) != 1:
171
-            parser.error("Incorrect arguments")
144
+    # Cleanup the working directory
145
+    if not options.force:
146
+        proceed = query_yes_no("This will remove everything under {0}. Are you sure?".format(options.working_directory))
147
+        if not proceed:
148
+            sys.exit(0)
172 149
 
173
-        # Read the conf file
174
-        config = (JsonWrapper(args[0])).read()
150
+    if options.src_iso_path:
151
+        rpm_list = create_rpm_list_to_be_copied_to_iso(options.pkg_to_rpm_map_file, options.package_list_file, 4, options.output_data_path)
152
+        make_src_iso(options.working_directory, options.src_iso_path, rpm_list)
175 153
 
176
-        config['iso_system'] = False
177
-        config['vmdk_install'] = False
154
+    else:
155
+        if options.iso_path:
156
+            # Check the arguments
157
+            if (len(args)) != 0:
158
+                parser.error("Incorrect arguments")
159
+            config = {}
160
+            config['iso_system'] = True
161
+            config['vmdk_install'] = False
162
+            config['type'] = 'iso'
163
+
164
+        elif options.vmdk_path:
165
+            # Check the arguments
166
+            if (len(args)) != 1:
167
+                parser.error("Incorrect arguments")
168
+
169
+            # Read the conf file
170
+            config = (JsonWrapper(args[0])).read()
171
+            config['disk'], success = create_vmdk_and_partition(config, options.vmdk_path)
172
+            if not success:
173
+                print "Unexpected failure, please check the logs"
174
+                sys.exit(1)
175
+
176
+            config['initrd_dir'] = "/boot"
177
+
178
+            config['iso_system'] = False
179
+            config['vmdk_install'] = True
178 180
 
179
-    if 'password' in config:
180
-        # crypt the password if needed
181
-        if config['password']['crypted']:
182
-            config['password'] = config['password']['text']
183 181
         else:
184
-            config['password'] = crypt.crypt(config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]))
182
+            # Check the arguments
183
+            if (len(args)) != 1:
184
+                parser.error("Incorrect arguments")
185 185
 
186
-    # Check the installation type
187
-    json_wrapper_option_list = JsonWrapper(options.package_list_file)
188
-    option_list_json = json_wrapper_option_list.read()
189
-    options_sorted = option_list_json.items()
190
-    base_path = os.path.dirname(options.package_list_file)
186
+            # Read the conf file
187
+            config = (JsonWrapper(args[0])).read()
191 188
 
192
-    packages = []
193
-    additional_files_to_copy_from_stage_to_iso = []
194
-    if config['iso_system'] == True:
195
-        for install_option in options_sorted:
196
-            if install_option[0] == "iso":
197
-                json_wrapper_package_list = JsonWrapper(os.path.join(base_path, install_option[1]["file"]))
198
-                package_list_json = json_wrapper_package_list.read()
199
-                packages = package_list_json["packages"]
200
-    else:
201
-        packages = PackageSelector.get_packages_to_install(options_sorted, config['type'], options.output_data_path)
189
+            config['iso_system'] = False
190
+            config['vmdk_install'] = False
202 191
 
203
-    config['packages'] = packages
192
+        if 'password' in config:
193
+            # crypt the password if needed
194
+            if config['password']['crypted']:
195
+                config['password'] = config['password']['text']
196
+            else:
197
+                config['password'] = crypt.crypt(config['password']['text'], "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]))
204 198
 
205
-    if options.iso_path:
206
-        if os.path.isfile(options.dracut_configuration_file):
207
-            json_wrapper_package_list = JsonWrapper(options.dracut_configuration_file)
208
-            dracut_configuration_list_json = json_wrapper_package_list.read()
209
-            config["dracut_configuration"]=dracut_configuration_list_json["dracut_configuration"]
199
+        # Check the installation type
200
+        json_wrapper_option_list = JsonWrapper(options.package_list_file)
201
+        option_list_json = json_wrapper_option_list.read()
202
+        options_sorted = option_list_json.items()
210 203
 
211
-    # Cleanup the working directory
212
-    if not options.force:
213
-        proceed = query_yes_no("This will remove everything under {0}. Are you sure?".format(options.working_directory))
214
-        if not proceed:
215
-            sys.exit(0)
204
+        packages = []
205
+        packages = PackageSelector.get_packages_to_install(options_sorted, config['type'], options.output_data_path)
216 206
 
217
-    if (os.path.isdir(options.working_directory)):
218
-        process = subprocess.Popen(['rm', '-rf', options.working_directory])
219
-        retval = process.wait()
220
-    else:
221
-        process = subprocess.Popen(['mkdir', '-p', options.working_directory])
222
-        retval = process.wait()
207
+        config['packages'] = packages
223 208
 
224
-    process = subprocess.Popen(['mkdir', '-p', os.path.join(options.working_directory, "photon-chroot")])
225
-    retval = process.wait()
209
+        if options.iso_path:
210
+            if os.path.isfile(options.dracut_configuration_file):
211
+                json_wrapper_package_list = JsonWrapper(options.dracut_configuration_file)
212
+                dracut_configuration_list_json = json_wrapper_package_list.read()
213
+                config["dracut_configuration"]=dracut_configuration_list_json["dracut_configuration"]
226 214
 
227
-    config['working_directory'] = options.working_directory
228 215
 
229
-    # Run the installer
230
-    package_installer = Installer(config, rpm_path = options.rpm_path, log_path = options.log_path)
231
-    package_installer.install(None)
216
+        if (os.path.isdir(options.working_directory)):
217
+            process = subprocess.Popen(['rm', '-rf', options.working_directory])
218
+            retval = process.wait()
232 219
 
233
-    # Making the iso if needed
234
-    if options.iso_path:
235
-        rpm_list = " ".join(create_rpm_list_to_copy_in_iso(options.package_list_file, options.output_data_path))
236
-        files_to_copy = " ".join(create_additional_file_list_to_copy_in_iso(os.path.abspath(options.stage_path), options.package_list_file))
237
-        live_cd = get_live_cd_status_string(options.package_list_file)
238
-        process = subprocess.Popen(['./mk-install-iso.sh', '-w', options.working_directory, options.iso_path, options.rpm_path, options.package_list_file, rpm_list, options.stage_path, files_to_copy, live_cd, options.json_data_path])
220
+        process = subprocess.Popen(['mkdir', '-p', os.path.join(options.working_directory, "photon-chroot")])
239 221
         retval = process.wait()
240 222
 
241
-    if options.src_iso_path:
242
-        rpm_list = " ".join(create_rpm_list_to_copy_in_iso(options.package_list_file, options.output_data_path))
243
-        process = subprocess.Popen(['./mk-src-iso.sh', '-w', options.working_directory, options.src_iso_path, options.srpm_path, rpm_list])
244
-        retval = process.wait()
245
-        list_rpms = rpm_list.split(" ")
246
-        list_rpms = list(set(list_rpms))
247
-        list_rpms.sort()
248
-
249
-    # Cleaning up for vmdk
250
-    if 'vmdk_install' in config and config['vmdk_install']:
251
-        process = subprocess.Popen(['./mk-clean-vmdk.sh', config['disk']['disk']])
252
-        process.wait()
253
-
254
-    #Clean up the working directories
255
-    if (options.iso_path or options.vmdk_path or options.src_iso_path):
256
-        process = subprocess.Popen(['rm', '-rf', options.working_directory])
257
-        retval = process.wait()
223
+        config['working_directory'] = options.working_directory
224
+
225
+        # Run the installer
226
+        package_installer = Installer(config, rpm_path = options.rpm_path, log_path = options.log_path)
227
+        package_installer.install(None)
228
+
229
+        # Making the iso if needed
230
+        if options.iso_path:
231
+            rpm_list = " ".join(create_rpm_list_to_be_copied_to_iso(options.pkg_to_rpm_map_file, options.package_list_file, 3, options.output_data_path))
232
+            files_to_copy = " ".join(create_additional_file_list_to_copy_in_iso(os.path.abspath(options.stage_path), options.package_list_file))
233
+            live_cd = get_live_cd_status_string(options.package_list_file)
234
+            process = subprocess.Popen(['./mk-install-iso.sh', '-w', options.working_directory, options.iso_path, options.rpm_path, options.package_list_file, rpm_list, options.stage_path, files_to_copy, live_cd, options.json_data_path])
235
+            retval = process.wait()
236
+
237
+        # Cleaning up for vmdk
238
+        if 'vmdk_install' in config and config['vmdk_install']:
239
+            process = subprocess.Popen(['./mk-clean-vmdk.sh', config['disk']['disk']])
240
+            process.wait()
241
+
242
+        #Clean up the working directories
243
+        if (options.iso_path or options.vmdk_path):
244
+            process = subprocess.Popen(['rm', '-rf', options.working_directory])
245
+            retval = process.wait()