~ibmcharmers/charms/trusty/layer-ibm-http/trunk

« back to all changes in this revision

Viewing changes to reactive/ibm_http.py

  • Committer: Shruthima Almavar
  • Date: 2016-08-11 10:04:00 UTC
  • Revision ID: salmavar@in.ibm.com-20160811100400-4xk9w3076rrk2gxn
Changes in README.md and reactive file

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
ARCHITECTURE= os.uname()
22
22
IM_INSTALL_PATH= '/opt/IBM/InstallationManager'
 
23
IHS_install_path = "/opt/IBM/HTTPServer"
 
24
PLG_install_path = "/opt/IBM/WebSphere/Plugins"
 
25
WCT_install_path = "/opt/IBM/WebSphere/Toolbox"
23
26
config = hookenv.config()
24
27
CHARM_DIR = os.getcwd()
25
28
 
27
30
@when_not ('ibm-http-server.installed')
28
31
def install_ibm_http():
29
32
        if not (("ppc64le" in ARCHITECTURE) or ("x86_64" in ARCHITECTURE)):
30
 
        #if not ("x86_64" or "ppc64le") in ARCHITECTURE:
31
33
                hookenv.log('IBM HTTP: only supported on x86_64 or ppc64le platforms', 'INFO')
32
34
                hookenv.status_set('blocked', 'IBM HTTP: unsupported architecture')
33
35
                sys.exit(1)
34
36
 
35
37
        # Fail fast if we're on an unsupported arch
36
 
        CHARM_DIR = os.getcwd()
37
38
        if "x86_64" in ARCHITECTURE:
38
39
                print ("architecture is x86_64")
39
40
                subprocess.check_call(['apt-get', 'install', '-y', 'libc6-i386'], stdout=open(os.devnull,'wb'), stderr=STDOUT)
42
43
                hookenv.log('IBM HTTP: fetching the ibm_http_installer1 resource', 'INFO')
43
44
                hookenv.status_set('active', 'fetching the ibm_http_installer1 resource')
44
45
                http_installer1 = hookenv.resource_get('ibm_http_installer1')
45
 
                hookenv.status_set('active', 'fetched ibm_http_installer1 resource')
46
46
 
47
47
                hookenv.log('IBM HTTP: fetching the ibm_http_installer2 resource', 'INFO')
48
48
                hookenv.status_set('active', 'fetching the ibm_http_installer2 resource')
52
52
                hookenv.status_set('active', 'fetching the ibm_http_installer3 resource')
53
53
                http_installer3 = hookenv.resource_get('ibm_http_installer3')
54
54
                
 
55
 
 
56
                # If we don't have a package, report blocked status; we can't proceed.
 
57
                if (http_installer1 == False or http_installer2 == False or http_installer3 == False):
 
58
                        hookenv.log('IBM HTTP: missing the required ibm_http resources', 'INFO')
 
59
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing')
 
60
                        sys.exit(0)
 
61
 
55
62
                command1 = ["file", http_installer1]
56
63
                p1 = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
57
64
                output1, err = p1.communicate()
61
68
                p2 = subprocess.Popen(command2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
62
69
                output2, err = p2.communicate()
63
70
                http_installer2_msg = str(output2)
64
 
 
 
71
                
65
72
                command3 = ["file", http_installer3]
66
73
                p3 = subprocess.Popen(command3, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
67
74
                output3, err = p3.communicate()
68
75
                http_installer3_msg = str(output3)
69
 
                
70
76
 
71
 
                # If we don't have a package, report blocked status; we can't proceed.
72
 
                if (http_installer1 == False or http_installer2 == False or http_installer3 == False):
73
 
                        hookenv.log('IBM HTTP: missing the required ibm_http resources', 'INFO')
74
 
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing')
75
 
                        sys.exit(0)
76
77
                if (("empty" in http_installer1_msg) or ("empty" in http_installer2_msg) or ("empty" in http_installer3_msg)):
77
78
                        hookenv.log('IBM HTTP: missing the required ibm_http resources,empty packages are found', 'INFO')
78
79
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing,Please provide the actual packages to install')
80
81
                else:           
81
82
                        http_server_installers = (http_installer1, http_installer2, http_installer3)
82
83
                        CHARM_DIR = os.getcwd()
83
 
                        os.makedirs(CHARM_DIR+"/../resources/HTTP")
 
84
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP"):
 
85
                                hookenv.log("IBM HTTP: dir exist already.")
 
86
                        else:
 
87
                                os.makedirs(CHARM_DIR+"/../resources/HTTP")
84
88
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP/disk1") and os.path.exists(CHARM_DIR+"/../resources/HTTP/disk2") and os.path.exists(CHARM_DIR+"/../resources/HTTP/disk3"):
85
 
                                hookenv.log("HTTP package contents extracted already.")
86
 
                        else:
87
 
                                for i in http_server_installers:
88
 
                                        filename = i
89
 
                                        hookenv.log("Extracting HTTP package contents.")
90
 
                                        with zipfile.ZipFile(filename) as z:
91
 
                                                z.extractall(CHARM_DIR+"/../resources/HTTP")
92
 
                                                hookenv.log("extracted")
93
 
                        #checking whether zip files extracted properly
94
 
                        if not os.path.exists(CHARM_DIR+"/../resources/HTTP/disk1") :
95
 
                                hookenv.log("IBM HTTP: Unable to extract the HTTP package content. Verify whether the package is corrupt")
96
 
                                hookenv.status_set('blocked', 'IBM HTTP Server package is corrupt')
97
 
                                shutil.rmtree(CHARM_DIR+"/../resources/HTTP")
98
 
                                sys.exit(0)
99
 
                        else:
100
 
                                hookenv.log("IBM HTTP: HTTP Server packages extracted successfully and available for installation")
101
 
                                http_repo = str(CHARM_DIR)+"/../resources/HTTP"
102
 
                                #Installtion
103
 
                                hookenv.status_set('active', "IBM HTTP Server: Installing HTTP Server")
 
89
                                hookenv.log("IBM HTTP: Package contents extracted already.")
 
90
                        else:
 
91
                                hookenv.log("IBM HTTP: Extracting HTTP package contents.")
 
92
                                #checking whether zip files extracted properly
104
93
                                try:
105
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.v85', '-repositories', http_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
106
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.v85', '-repositories', http_repo, '-acceptLicense'])
107
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.v85', '-repositories', http_repo, '-acceptLicense'])
108
 
                                        hookenv.status_set('active', "IBM HTTP: HTTP Server is installed successfully")
109
 
                                        set_state('ibm-http-server.installed')
 
94
                                        for i in http_server_installers:
 
95
                                                filename = i
 
96
                                                with zipfile.ZipFile(filename) as z:
 
97
                                                        z.extractall(CHARM_DIR+"/../resources/HTTP")
 
98
                                                        hookenv.log("IBM HTTP: HTTP Server packages extracted successfully and available for installation")
110
99
                                except subprocess.CalledProcessError as e:
111
100
                                        print(e.output)
112
 
                                        hookenv.status_set('maintenance', "IBM HTTP Server: Error while installing HTTP")
113
 
                                        sys.exit(1)
 
101
                                        hookenv.log("IBM HTTP: Unable to extract the HTTP package content. Verify whether the package is corrupt")
 
102
                                        hookenv.status_set('blocked', 'IBM HTTP Server package is corrupt')
 
103
                                        shutil.rmtree(CHARM_DIR+"/../resources/HTTP")
 
104
                                        sys.exit(0)
 
105
                        #Installtion
 
106
                        http_repo = str(CHARM_DIR)+"/../resources/HTTP"
 
107
                        hookenv.status_set('active', "IBM HTTP: Installing HTTP Server")
 
108
                        try:
 
109
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.v85', '-installationDirectory', IHS_install_path, '-repositories', http_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
 
110
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.v85', '-installationDirectory', PLG_install_path, '-repositories', http_repo, '-acceptLicense'])
 
111
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.v85', '-installationDirectory', WCT_install_path, '-repositories', http_repo, '-acceptLicense'])
 
112
                                hookenv.status_set('active', "IBM HTTP: HTTP Server is installed successfully")
 
113
                                set_state('ibm-http-server.installed')
 
114
                        except subprocess.CalledProcessError as e:
 
115
                                print(e.output)
 
116
                                hookenv.status_set('maintenance', "IBM HTTP: Error while installing HTTP")
 
117
                                sys.exit(1)
114
118
 
115
119
        elif "ppc64le" in ARCHITECTURE:
116
120
                print ("architecture is ppc64le")
118
122
                hookenv.log('IBM HTTP: fetching the ibm__http_power_installer resource', 'INFO')
119
123
                hookenv.status_set('active', 'fetching the ibm_http_power_installer resource')
120
124
                http_power_installer = hookenv.resource_get('ibm_http_power_installer')
121
 
                hookenv.status_set('active', 'fetched ibm_http_power_installer resource')
 
125
                
 
126
                # If we don't have a package, report blocked status; we can't proceed.
 
127
                if (http_power_installer == False):
 
128
                        hookenv.log('IBM HTTP: missing the required ibm_http resources', 'INFO')
 
129
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing')
 
130
                        sys.exit(0)
122
131
                
123
132
                command = ["file", http_power_installer]
124
133
                p1 = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
125
134
                output, err = p1.communicate()
126
135
                http_power_installer_msg = str(output)
127
136
 
128
 
                # If we don't have a package, report blocked status; we can't proceed.
129
 
                if (http_power_installer == False):
130
 
                        hookenv.log('IBM HTTP: missing the required ibm_http resources', 'INFO')
131
 
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing')
132
 
                        sys.exit(0)
133
137
                if "empty" in http_power_installer_msg:
134
138
                        hookenv.log('IBM HTTP: missing the required ibm_http resources,empty packages are found', 'INFO')
135
139
                        hookenv.status_set('blocked', 'IBM HTTP Server required packages are  missing.Please provide actual packages to install')
136
140
                        sys.exit(0)
137
141
                else:
138
142
                        CHARM_DIR = os.getcwd()
139
 
                        os.makedirs(CHARM_DIR+"/../resources/HTTP")
140
 
                        print ("HTTP created")
 
143
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP"):
 
144
                                hookenv.log("IBM HTTP: dir exist already.")
 
145
                        else:
 
146
                                os.makedirs(CHARM_DIR+"/../resources/HTTP")
141
147
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP/disk1"):
142
 
                                hookenv.log("HTTP package contents extracted already.")
143
 
                        else:
144
 
                                zip_ref = zipfile.ZipFile(http_power_installer, 'r')
145
 
                                zip_ref.extractall(CHARM_DIR+"/../resources/HTTP")
146
 
                                zip_ref.close()
147
 
                                hookenv.log("extracted")
148
 
                                
149
 
                        #checking whether zip files extracted properly
150
 
                        if not os.path.exists(CHARM_DIR+"/../resources/HTTP/disk1") :
151
 
                                hookenv.log("IBM HTTP: Unable to extract the HTTP package content. Verify whether the package is corrupt")
152
 
                                hookenv.status_set('blocked', 'IBM HTTP Server package is corrupt')
153
 
                                shutil.rmtree(CHARM_DIR+"/../resources/HTTP")
154
 
                                sys.exit(0)
155
 
                        else:
156
 
                                hookenv.log("IBM HTTP: HTTP Server packages extracted successfully and available for installation")
157
 
                                http_repo = str(CHARM_DIR)+"/../resources/HTTP"
158
 
                                #Installtion
159
 
                                hookenv.status_set('active', "IBM HTTP Server: Installing HTTP Server")
 
148
                                hookenv.log("IBM HTTP: package contents extracted already.")
 
149
                        else:
 
150
                                hookenv.log("IBM HTTP: Extracting HTTP package contents.")
 
151
                                #checking whether zip files extracted properly
160
152
                                try:
161
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.le.v85', '-repositories', http_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
162
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.le.v85', '-repositories', http_repo, '-acceptLicense'])
163
 
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.le.v85', '-repositories', http_repo, '-acceptLicense'])
164
 
                                        hookenv.status_set('active', "IBM HTTP: HTTP Server is installed successfully")
165
 
                                        set_state('ibm-http-server.installed')
 
153
                                        zip_ref = zipfile.ZipFile(http_power_installer, 'r')
 
154
                                        zip_ref.extractall(CHARM_DIR+"/../resources/HTTP")
 
155
                                        zip_ref.close()
 
156
                                        hookenv.log("IBM HTTP: HTTP Server packages extracted successfully and available for installation")
166
157
                                except subprocess.CalledProcessError as e:
167
158
                                        print(e.output)
168
 
                                        hookenv.status_set('maintenance', "IBM HTTP Server: Error while installing HTTP")
169
 
                                        sys.exit(1)
 
159
                                        hookenv.log("IBM HTTP: Unable to extract the HTTP package content. Verify whether the package is corrupt")
 
160
                                        hookenv.status_set('blocked', 'IBM HTTP Server package is corrupt')
 
161
                                        shutil.rmtree(CHARM_DIR+"/../resources/HTTP")
 
162
                                        sys.exit(0)
 
163
                        #Installtion
 
164
                        http_repo = str(CHARM_DIR)+"/../resources/HTTP"
 
165
                        hookenv.status_set('active', "IBM HTTP: Installing HTTP Server")
 
166
                        try:
 
167
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.le.v85', '-installationDirectory', IHS_install_path, '-repositories', http_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
 
168
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.le.v85', '-installationDirectory', PLG_install_path, '-repositories', http_repo, '-acceptLicense'])
 
169
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.le.v85', '-installationDirectory', WCT_install_path, '-repositories', http_repo, '-acceptLicense'])
 
170
                                hookenv.status_set('active', "IBM HTTP: HTTP Server is installed successfully")
 
171
                                set_state('ibm-http-server.installed')
 
172
                        except subprocess.CalledProcessError as e:
 
173
                                print(e.output)
 
174
                                hookenv.status_set('maintenance', "IBM HTTP: Error while installing HTTP")
 
175
                                sys.exit(1)
170
176
 
171
177
@when ('ibm-http-server.installed')
172
178
@when_not ('ibm-http-server.updated')
193
199
        http_WCT_fixpack2 = hookenv.resource_get('ibm_http_server_WCT_fixpack2')
194
200
        hookenv.status_set('active', 'fetched ibm_http_server_WCT_fixpack2 resource')
195
201
        
196
 
        print (http_fixpack1)
197
 
        print (http_fixpack2)
198
202
 
199
203
        # If we don't have a fixpack, just exit successfully; there's nothing to do.
200
204
        if (http_fixpack1 == False or http_fixpack2 == False or http_WCT_fixpack1 == False or http_WCT_fixpack2 == False):
223
227
                http_fixpack_msg4 = str(output4)
224
228
 
225
229
                if (("empty" in http_fixpack_msg1) or ("empty" in http_fixpack_msg2) or ("empty" in http_fixpack_msg3) or ("empty" in http_fixpack_msg4)):              
226
 
                        hookenv.log('IBM HTTP: no ibm_http_server_fixpack to install', 'INFO')
 
230
                        hookenv.log('IBM HTTP: no ibm_http_server_fixpack to install,empty packages found', 'INFO')
227
231
                        hookenv.status_set('active', 'IBM HTTP is ready')
228
232
                        sys.exit(0)
229
233
                else:
230
234
                        http_fixpack_installers = (http_fixpack1, http_fixpack2)
231
235
                        http_WCT_fixpack_installers = (http_WCT_fixpack1, http_WCT_fixpack2)
232
236
                        CHARM_DIR = os.getcwd()
233
 
                        os.makedirs(CHARM_DIR+"/../resources/HTTP_FP")
234
 
                        os.makedirs(CHARM_DIR+"/../resources/HTTP_WCT_FP")
235
 
                        print ("HTTP_FP and HTTP_WCT_FP created")
236
 
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP_FP/disk1"):
237
 
                                hookenv.log("HTTP fixpack_package contents extracted already.")
238
 
                        else:
 
237
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP_FP"):
 
238
                                hookenv.log("HTTP_FP dir exist already.")
 
239
                        else:
 
240
                                os.makedirs(CHARM_DIR+"/../resources/HTTP_FP")
 
241
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP_WCT_FP"):
 
242
                                hookenv.log("HTTP_WCT_FP dir exist already.")
 
243
                        else:
 
244
                                os.makedirs(CHARM_DIR+"/../resources/HTTP_WCT_FP")
 
245
                        hookenv.log("Extracting HTTP fixpack package contents.")
 
246
                        #checking whether zip files extracted properly
 
247
                        try:
239
248
                                for i in http_fixpack_installers:
240
249
                                        filename = i
241
 
                                        print (filename)
242
 
                                        hookenv.log("Extracting HTTP fixpack package contents.")
 
250
                                        hookenv.log("IBM HTTP: Extracting HTTP fixpack package contents.")
243
251
                                        with zipfile.ZipFile(filename) as z:
244
252
                                                z.extractall(CHARM_DIR+"/../resources/HTTP_FP")
245
 
                                                hookenv.log("extracted")
246
 
                        if os.path.exists(CHARM_DIR+"/../resources/HTTP_WCT_FP/Offerings"):
247
 
                                hookenv.log("HTTP fixpack_WCT_package contents extracted already.")
248
 
                        else:
 
253
                                                hookenv.log("IBM HTTP: HTTP_FP Server packages extracted successfully")
 
254
                        except subprocess.CalledProcessError as e:
 
255
                                print(e.output)
 
256
                                hookenv.log("IBM HTTP: Unable to extract the HTTP_FP package content. Verify whether the package is corrupt")
 
257
                                hookenv.status_set('blocked', 'IBM HTTP_FP Server package is corrupt')
 
258
                                shutil.rmtree(CHARM_DIR+"/../resources/HTTP_FP")
 
259
                                sys.exit(0)
 
260
                        hookenv.log("IBM HTTP: Extracting HTTP WCT fixpack package contents.")
 
261
                        try:
249
262
                                for i in http_WCT_fixpack_installers:
250
263
                                        filename = i
251
 
                                        print (filename)
252
 
                                        hookenv.log("Extracting HTTP WCT fixpack package contents.")
 
264
                                        hookenv.log("IBM HTTP: Extracting HTTP WCT fixpack package contents.")
253
265
                                        with zipfile.ZipFile(filename) as z:
254
266
                                                z.extractall(CHARM_DIR+"/../resources/HTTP_WCT_FP")
255
 
                                                hookenv.log("extracted")
256
 
                        
257
 
        #checking whether zip files extracted properly
258
 
        if not os.path.exists(CHARM_DIR+"/../resources/HTTP_WCT_FP"):
259
 
                hookenv.log("IBM HTTP: Unable to extract the HTTP_FP package content. Verify whether the package is corrupt")
260
 
                hookenv.status_set('blocked', 'IBM HTTP_FP Server package is corrupt')
261
 
                sys.exit(0)
262
 
        else:
263
 
                hookenv.log("IBM HTTP: HTTP_FP Server packages extracted successfully and available for installation")
264
 
                http_FP_repo = str(CHARM_DIR)+"/../resources/HTTP_FP"
265
 
                http_WCT_FP_repo = str(CHARM_DIR)+"/../resources/HTTP_WCT_FP"
266
 
                #Updation
267
 
                hookenv.status_set('active', "IBM HTTP Server: Updating HTTP Server")
268
 
                if "x86_64" in ARCHITECTURE:
269
 
                        try:
270
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.v85', '-repositories', http_FP_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
271
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.v85', '-repositories', http_FP_repo, '-acceptLicense'])
272
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.v85', '-repositories', http_WCT_FP_repo, '-acceptLicense'])
273
 
                                hookenv.status_set('active', "IBM HTTP: HTTP Server is updated successfully")
274
 
                                set_state('ibm-http-server.updated')
275
 
                        except subprocess.CalledProcessError as e:
276
 
                                print(e.output)
277
 
                                hookenv.status_set('maintenance', "IBM HTTP Server: Error while updating HTTP")
278
 
                                sys.exit(1)
279
 
                elif "ppc64le" in ARCHITECTURE:
280
 
                        try:
281
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.le.v85', '-repositories', http_FP_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
282
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.le.v85', '-repositories', http_FP_repo, '-acceptLicense'])
283
 
                                subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.le.v85', '-repositories', http_WCT_FP_repo, '-acceptLicense'])
284
 
                                hookenv.status_set('active', "IBM HTTP: HTTP Server is updated successfully")
285
 
                                set_state('ibm-http-server.updated')
286
 
                        except subprocess.CalledProcessError as e:
287
 
                                print(e.output)
288
 
                                hookenv.status_set('maintenance', "IBM HTTP Server: Error while updating HTTP")
289
 
                                sys.exit(1)
 
267
                                                hookenv.log("IBM HTTP: HTTP_WCT_FP Server packages extracted successfully")
 
268
                        except subprocess.CalledProcessError as e:
 
269
                                print(e.output)
 
270
                                hookenv.log("IBM HTTP: Unable to extract the HTTP_WCT_FP package content. Verify whether the package is corrupt")
 
271
                                hookenv.status_set('blocked', 'IBM HTTP_WCT_FP Server package is corrupt')
 
272
                                shutil.rmtree(CHARM_DIR+"/../resources/HTTP_WCT_FP")
 
273
                                sys.exit(0)
 
274
                        #Updation       
 
275
                        http_FP_repo = str(CHARM_DIR)+"/../resources/HTTP_FP"
 
276
                        http_WCT_FP_repo = str(CHARM_DIR)+"/../resources/HTTP_WCT_FP"
 
277
                        hookenv.status_set('active', "IBM HTTP: Updating HTTP Server")
 
278
                        if "x86_64" in ARCHITECTURE:
 
279
                                try:
 
280
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.v85', '-installationDirectory', IHS_install_path, '-repositories', http_FP_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
 
281
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.v85', '-installationDirectory', PLG_install_path, '-repositories', http_FP_repo, '-acceptLicense'])
 
282
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.v85', '-installationDirectory', WCT_install_path, '-repositories', http_WCT_FP_repo, '-acceptLicense'])
 
283
                                        hookenv.status_set('active', "IBM HTTP: HTTP Server is updated successfully")
 
284
                                        set_state('ibm-http-server.updated')
 
285
                                except subprocess.CalledProcessError as e:
 
286
                                        print(e.output)
 
287
                                        hookenv.status_set('maintenance', "IBM HTTP: Error while updating HTTP")
 
288
                                        sys.exit(1)
 
289
                        elif "ppc64le" in ARCHITECTURE:
 
290
                                try:
 
291
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.IHS.le.v85', '-installationDirectory', IHS_install_path, '-repositories', http_FP_repo, '-acceptLicense', '-properties', 'user.ihs.httpPort=80'])
 
292
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.PLG.le.v85', '-installationDirectory', PLG_install_path, '-repositories', http_FP_repo, '-acceptLicense'])
 
293
                                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'install', 'com.ibm.websphere.WCT.le.v85', '-installationDirectory', WCT_install_path, '-repositories', http_WCT_FP_repo, '-acceptLicense'])
 
294
                                        hookenv.status_set('active', "IBM HTTP: HTTP Server is updated successfully")
 
295
                                        set_state('ibm-http-server.updated')
 
296
                                except subprocess.CalledProcessError as e:
 
297
                                        print(e.output)
 
298
                                        hookenv.status_set('maintenance', "IBM HTTP: Error while updating HTTP")
 
299
                                        sys.exit(1)
290
300
 
291
301
@hook('upgrade-charm')
292
302
def check_fixpack():
299
309
                CHARM_DIR = os.getcwd()
300
310
                ARCHIVE_DIR1 = str(CHARM_DIR)+"/../resources/ibm_http_server_fixpack1"
301
311
                ARCHIVE_DIR2 = str(CHARM_DIR)+"/../resources/ibm_http_server_fixpack2"
 
312
                ARCHIVE_DIR3 = str(CHARM_DIR)+"/../resources/ibm_http_server_WCT_fixpack1"
 
313
                ARCHIVE_DIR4 = str(CHARM_DIR)+"/../resources/ibm_http_server_WCT_fixpack2"
302
314
                CUR_FIXPACK1 = str(ARCHIVE_DIR1)+"/ibm_http_server_fixpack1.zip"
303
315
                CUR_FIXPACK2 = str(ARCHIVE_DIR2)+"/ibm_http_server_fixpack2.zip"
 
316
                CUR_FIXPACK3 = str(ARCHIVE_DIR3)+"/ibm_http_server_WCT_fixpack1.zip"
 
317
                CUR_FIXPACK4 = str(ARCHIVE_DIR4)+"/ibm_http_server_WCT_fixpack2.zip"
304
318
 
305
319
                # Sum any existing fixpack to determine if we have a new one
306
 
                if os.path.exists(ARCHIVE_DIR1+"/ibm_http_server_fixpack1.zip") and os.path.exists(ARCHIVE_DIR2+"/ibm_http_server_fixpack2.zip"):
 
320
                if (os.path.exists(ARCHIVE_DIR1+"/ibm_http_server_fixpack1.zip") and os.path.exists(ARCHIVE_DIR2+"/ibm_http_server_fixpack2.zip") and os.path.exists(ARCHIVE_DIR3+"/ibm_http_server_WCT_fixpack1.zip") and os.path.exists(ARCHIVE_DIR4+"/ibm_http_server_WCT_fixpack2.zip")):
 
321
                        hookenv.log("IBM HTTP: Checking checksum values of CUR_Fixpacks")
307
322
                        command1 = ["md5sum", CUR_FIXPACK1]
308
323
                        p1 = subprocess.Popen(command1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
309
324
                        output1, err = p1.communicate()
310
 
                        CUR_FP1_MD5 = str(output1)
311
 
                        print (CUR_FP1_MD5)
 
325
                        value1  = output1.split()
 
326
                        CUR_FP1_MD5 = str(value1[0]) 
312
327
 
313
328
                        command2 = ["md5sum", CUR_FIXPACK2]
314
329
                        p2 = subprocess.Popen(command2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
315
330
                        output2, err = p2.communicate()
316
 
                        CUR_FP2_MD5 = str(output2)
317
 
                        print (CUR_FP2_MD5)
 
331
                        value2  = output2.split()
 
332
                        CUR_FP2_MD5 = str(value2[0])
 
333
                        
 
334
                        command3 = ["md5sum", CUR_FIXPACK3]
 
335
                        p3 = subprocess.Popen(command3, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
336
                        output3, err = p3.communicate()
 
337
                        value3  = output3.split()
 
338
                        CUR_FP3_MD5 = str(value3[0])
 
339
                        
 
340
                        command4 = ["md5sum", CUR_FIXPACK4]
 
341
                        p4 = subprocess.Popen(command4, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
342
                        output4, err = p4.communicate()
 
343
                        value4  = output4.split()
 
344
                        CUR_FP4_MD5 = str(value4[0])
318
345
                        
319
346
                        # Calling resource-get here will fetch the fixpack resource.
320
347
                        NEW_FIXPACK1 = hookenv.resource_get('ibm_http_server_fixpack1')
321
348
                        NEW_FIXPACK2 = hookenv.resource_get('ibm_http_server_fixpack2')
322
 
                        if (NEW_FIXPACK1 == False or  NEW_FIXPACK2 == False):
323
 
                                hookenv.log("IBM Http: no fixpack to install")
 
349
                        NEW_FIXPACK3 = hookenv.resource_get('ibm_http_server_WCT_fixpack1')
 
350
                        NEW_FIXPACK4 = hookenv.resource_get('ibm_http_server_WCT_fixpack2')
 
351
                        if (NEW_FIXPACK1 == False or  NEW_FIXPACK2 == False or NEW_FIXPACK3 == False or NEW_FIXPACK4 == False):
 
352
                                hookenv.log("IBM HTTP: no fixpack to install")
324
353
                        else:
325
 
                                command3 = ["md5sum", NEW_FIXPACK1]
326
 
                                p3 = subprocess.Popen(command3, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
327
 
                                output3, err = p3.communicate()
328
 
                                NEW_FP1_MD5 = str(output3)
329
 
                                print (NEW_FP1_MD5)
330
 
 
331
 
                                command4 = ["md5sum", NEW_FIXPACK2]
332
 
                                p4 = subprocess.Popen(command4, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
333
 
                                output4, err = p4.communicate()
334
 
                                NEW_FP2_MD5 = str(output4)
335
 
                                print (NEW_FP2_MD5)                     
 
354
                                hookenv.log("IBM HTTP: Checking checksum of NEW_FIXPACKS")
 
355
                                command5 = ["md5sum", NEW_FIXPACK1]
 
356
                                p5 = subprocess.Popen(command5, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
357
                                output5, err = p5.communicate()
 
358
                                value5  = output5.split()
 
359
                                NEW_FP1_MD5 = str(value5[0])
 
360
 
 
361
                                command6 = ["md5sum", NEW_FIXPACK2]
 
362
                                p6 = subprocess.Popen(command6, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
363
                                output6, err = p6.communicate()
 
364
                                value6  = output6.split()
 
365
                                NEW_FP2_MD5 = str(value6[0])
 
366
 
 
367
                                command7 = ["md5sum", NEW_FIXPACK3]
 
368
                                p7 = subprocess.Popen(command7, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
369
                                output7, err = p7.communicate()
 
370
                                value7  = output7.split()
 
371
                                NEW_FP3_MD5 = str(value7[0])
 
372
 
 
373
                                command8 = ["md5sum", NEW_FIXPACK4]
 
374
                                p8 = subprocess.Popen(command8, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
 
375
                                output8, err = p8.communicate()
 
376
                                value8  = output8.split()
 
377
                                NEW_FP4_MD5 = str(value8[0])
 
378
                
336
379
                                # If sums don't match, we have a new fp. Configure states so
337
 
                                # we re-run install-ibm-im-fixpack().
338
 
                                if not ((CUR_FP1_MD5 == NEW_FP1_MD5) or (CUR_FP2_MD5 == NEW_FP2_MD5)):
339
 
                                        hookenv.log("IBM HTTP: new fixpack detected")
 
380
                                # we re-run install-ibm-http-server-fixpack().
 
381
                                if (CUR_FP1_MD5 != NEW_FP1_MD5 or CUR_FP2_MD5 != NEW_FP2_MD5 or CUR_FP3_MD5 != NEW_FP3_MD5 or CUR_FP4_MD5 != NEW_FP4_MD5):
 
382
                                        hookenv.log("IBM HTTP: new fixpack detected "+CUR_FP1_MD5+"versus"+NEW_FP1_MD5+""+CUR_FP2_MD5+"versus"+NEW_FP2_MD5+""+CUR_FP3_MD5+"versus"+NEW_FP3_MD5+""+CUR_FP4_MD5+"versus"+NEW_FP4_MD5 )
340
383
                                        remove_state ('ibm-http-server.updated')
341
384
                                        shutil.rmtree(CHARM_DIR+"/../resources/HTTP_FP")
 
385
                                        shutil.rmtree(CHARM_DIR+"/../resources/HTTP_WCT_FP")
342
386
                                else:
343
 
                                        hookenv.log("IBM HTTP: no new fixpack to install")
 
387
                                        hookenv.log("IBM HTTP: no new fixpacks to install")
344
388
                else:
345
389
                        hookenv.log("IBM HTTP: no new fixpack to install")
346
390
 
356
400
        ihsadminpw = str(ihs.get_ihsadminpw())
357
401
        ihsadmingrp = str(ihs.get_ihsadmingrp())
358
402
        profilename = str(ihs.get_was_profile_name())
359
 
        hookenv.log("I got the was values"+was_install_path+""+hostname+""+ihsadminusr+""+ihsadminpw+""+ihsadmingrp+""+profilename)
360
 
        hookenv.status_set("maintenance", "was values copied from remote WAS Base machine")
 
403
        hookenv.log("Copied WAS values"+was_install_path+""+hostname+""+ihsadminusr+""+ihsadminpw+""+ihsadmingrp+""+profilename)
 
404
        hookenv.status_set("maintenance", "WAS values copied from remote WAS Base machine")
361
405
        set_state ('test.configured')
362
 
        plugin_path = '/root/IBM/WebSphere/Toolbox/WCT'
 
406
        plugin_path = '/opt/IBM/WebSphere/Toolbox/WCT'
363
407
        os.chdir( plugin_path )
364
408
        text_file = open("res.txt","w")
365
409
        lines = ["configType=local_standalone\n",
374
418
        "mapWebServerToApplications=true\n"
375
419
        "profileName="+profilename+"\n"
376
420
        "wasExistingLocation="+was_install_path+"\n"
377
 
        "webServerConfigFile1=/root/IBM/HTTPServer/conf/httpd.conf\n"
 
421
        "webServerConfigFile1=/opt/IBM/HTTPServer/conf/httpd.conf\n"
378
422
        "webServerDefinition=webserver1\n"
379
423
        "webServerHostName="+hostname+"\n"
380
424
        "webServerOS=Linux\n"
383
427
        text_file.writelines(lines)
384
428
        text_file.close()
385
429
        try:    
386
 
                subprocess.check_call(['/root/IBM/WebSphere/Toolbox/WCT/wctcmd.sh', '-tool', 'pct', '-defLocPathname', '/root/IBM/WebSphere/Plugins', '-defLocName', 'wasplg', '-createDefinition', '-response', '/root/IBM/WebSphere/Toolbox/WCT/res.txt'])
387
 
                http_path = '/root/IBM/HTTPServer/bin'
 
430
                subprocess.check_call(['/opt/IBM/WebSphere/Toolbox/WCT/wctcmd.sh', '-tool', 'pct', '-defLocPathname', '/opt/IBM/WebSphere/Plugins', '-defLocName', 'wasplg', '-createDefinition', '-response', '/opt/IBM/WebSphere/Toolbox/WCT/res.txt'])
 
431
                http_path = '/opt/IBM/HTTPServer/bin'
388
432
                subprocess.check_call([http_path +'/apachectl','start'])
389
 
                subprocess.call(['chmod', '-R', '755', '/root/IBM/HTTPServer/'])
 
433
                subprocess.check_call([http_path +'/adminctl','start'])
 
434
                subprocess.call(['chmod', '-R', '755', '/opt/IBM/HTTPServer/'])
390
435
                hookenv.status_set('active', "IBM HTTP: HTTP Server started successfully")
391
436
                ihs.set_isihsstarted('started')
392
437
        except subprocess.CalledProcessError as e:
393
438
                print(e.output)
394
 
                hookenv.status_set('maintenance', "IBM HTTP Server: Error while installing HTTP Server")
 
439
                hookenv.status_set('maintenance', "IBM HTTP: Error while starting HTTP Server")
 
440
 
 
441
 
395
442
@when('test.configured')
396
443
@when_not('ihs.ready')
397
444
def reset_all_states():
398
445
        hookenv.log("Resetting all states for test charm")
399
446
        remove_state('test.configured')
400
447
 
 
448
 
401
449
@when('ihs.departed')
402
450
def departed_from_was(self):
403
451
        hookenv.status_set("maintenance","Relation broken from WAS Base")
404
 
        http_path = '/root/IBM/HTTPServer/bin'
405
 
        subprocess.check_call([http_path +'/apachectl','stop'])
406
 
        hookenv.log("Stopped apachectl server.......")
 
452
        http_path = '/opt/IBM/HTTPServer/bin'
 
453
        if os.path.exists(http_path):
 
454
                subprocess.check_call([http_path +'/apachectl','stop'])
 
455
                subprocess.check_call([http_path +'/adminctl','stop'])
 
456
                hookenv.log("Stopped adminctl and apachectl server")
 
457
        else:
 
458
                hookenv.log("Stopped adminctl and apachectl server")
 
459
        if os.path.exists(WCT_install_path):
 
460
                subprocess.check_call(['/opt/IBM/WebSphere/Toolbox/WCT/wctcmd.sh', '-tool', 'pct', ' -removeDefinitionLocation', 'wasplg', '-defLocPathname', '/opt/IBM/WebSphere/Plugins'])
 
461
                hookenv.log("Removed webserver definition")
 
462
        else:
 
463
                hookenv.log("Removed webserver definition")
407
464
        hookenv.log("Test charm and WAS Base departed")
408
465
        hookenv.log("IBM HTTP: Removing HTTP-Server")
409
466
        if "x86_64" in ARCHITECTURE:
410
467
                try:
411
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.IHS.v85'])
412
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.PLG.v85'])
413
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.WCT.v85'])
 
468
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.IHS.v85', '-installationDirectory', IHS_install_path])
 
469
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.PLG.v85', '-installationDirectory', PLG_install_path])
 
470
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.WCT.v85', '-installationDirectory', WCT_install_path])
414
471
                        hookenv.status_set('active', "IBM HTTP: HTTP Server is uninstalled successfully")
415
 
                        shutil.rmtree('/root/IBM/HTTPServer')
416
 
                        shutil.rmtree('/root/IBM/WebSphere/Plugins')
417
 
                        shutil.rmtree('/root/IBM/WebSphere/Toolbox')
 
472
                        shutil.rmtree('/opt/IBM/HTTPServer')
 
473
                        shutil.rmtree('/opt/IBM/WebSphere/Plugins')
 
474
                        shutil.rmtree('/opt/IBM/WebSphere/Toolbox')
418
475
                        remove_state ('test.configured')
419
476
                except subprocess.CalledProcessError as e:
420
477
                        print(e.output)
421
 
                        hookenv.status_set('maintenance', "IBM HTTP Server: Error while uninstalling HTTP")
 
478
                        hookenv.status_set('maintenance', "IBM HTTP: Error while uninstalling HTTP")
422
479
        elif "ppc64le" in ARCHITECTURE:
423
480
                try:
424
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.IHS.le.v85'])
425
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.PLG.le.v85'])
426
 
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.WCT.le.v85'])
 
481
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.IHS.le.v85', '-installationDirectory', IHS_install_path])
 
482
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.PLG.le.v85', '-installationDirectory', PLG_install_path])
 
483
                        subprocess.check_call([IM_INSTALL_PATH +'/eclipse/tools/imcl', 'uninstall', 'com.ibm.websphere.WCT.le.v85', '-installationDirectory', WCT_install_path])
427
484
                        hookenv.status_set('active', "IBM HTTP: HTTP Server is uninstalled successfully")
428
 
                        shutil.rmtree('/root/IBM/HTTPServer')
429
 
                        shutil.rmtree('/root/IBM/WebSphere/Plugins')
430
 
                        shutil.rmtree('/root/IBM/WebSphere/Toolbox')
 
485
                        shutil.rmtree('/opt/IBM/HTTPServer')
 
486
                        shutil.rmtree('/opt/IBM/WebSphere/Plugins')
 
487
                        shutil.rmtree('/opt/IBM/WebSphere/Toolbox')
431
488
                        remove_state ('test.configured')
432
489
                except subprocess.CalledProcessError as e:
433
490
                        print(e.output)
434
 
                        hookenv.status_set('maintenance', "IBM HTTP Server: Error while uninstalling HTTP")
 
491
                        hookenv.status_set('maintenance', "IBM HTTP: Error while uninstalling HTTP")