blob: da4f8875d80495bdd765e9d52c3cf51bf1886ed5 [file] [log] [blame]
Zack Williamsce63eb02017-02-28 10:46:22 -07001# CORD Master Makefile
2
3# Timestamp for log files
4TS := $(shell date +'%Y%m%dT%H%M%SZ')
5
6# Podconfig must be specified, so an invalid default
7PODCONFIG ?= invalid
8
9# Source path
10BUILD ?= .
11CORD ?= ..
12PI ?= $(BUILD)/platform-install
13MAAS ?= $(BUILD)/maas
14
15# Configuration paths
16PODCONFIG_D ?= $(BUILD)/podconfig
17PODCONFIG_PATH ?= $(PODCONFIG_D)/$(PODCONFIG)
18
19SCENARIOS_D ?= $(BUILD)/scenarios
20GENCONFIG_D ?= $(BUILD)/genconfig
21
22# Milestones/logs paths
23M ?= $(BUILD)/milestones
24LOGS ?= $(BUILD)/logs
25
26ALL_MILESTONES ?= $(M)/prereqs-check $(M)/vagrant-up $(M)/copy-cord $(M)/cord-config $(M)/copy-config $(M)/prep-buildnode $(M)/prep-headnode $(M)/elasticstack $(M)/prep-computenode $(M)/glance-images $(M)/deploy-openstack $(M)/deploy-maas $(M)/deploy-computenode $(M)/docker-images $(M)/core-image $(M)/start-xos $(M)/onboard-profile $(M)/deploy-onos $(M)/onboard-openstack
27
28LOCAL_MILESTONES ?= $(M)/local-cord-config $(M)/local-docker-images $(M)/local-core-image $(M)/local-start-xos $(M)/local-onboard-profile
29
30# Configuration files
31MASTER_CONFIG ?= $(GENCONFIG_D)/config.yml
32MAKEFILE_CONFIG ?= $(GENCONFIG_D)/config.mk
33INVENTORY ?= $(GENCONFIG_D)/inventory.ini
34PROFILE_NAME_F ?= $(GENCONFIG_D)/cord_profile
35SCENARIO_NAME_F ?= $(GENCONFIG_D)/cord_scenario
36
37CONFIG_FILES = $(MASTER_CONFIG) $(MAKEFILE_CONFIG) $(INVENTORY) $(PROFILE_NAME_F) $(SCENARIO_NAME_F)
38
39include $(MAKEFILE_CONFIG)
40
41# Set using files from genconfig
42SCENARIO = $(shell cat $(SCENARIO_NAME_F))
43PROFILE = $(shell cat $(PROFILE_NAME_F))
44
45# Host names for SSH commands
46BUILDNODE ?= head1
47HEADNODE ?= ${BUILDNODE}
48
49# Vagrant config
50VAGRANT_PROVIDER ?= libvirt
51VAGRANT_VMS ?= $(HEADNODE)
52VAGRANT_CWD ?= $(SCENARIOS_D)/$(SCENARIO)/
53SSH_CONFIG ?= ~/.ssh/config # Vagrant modifies this, should it always?
54
55# Ansible args, for verbosity and other runtime parameters
56ANSIBLE_ARGS ?=
57
58# Commands
59SHELL = bash -o pipefail
60VAGRANT ?= VAGRANT_CWD=$(VAGRANT_CWD) vagrant
61ANSIBLE ?= ansible -i $(INVENTORY)
62ANSIBLE_PB ?= ansible-playbook $(ANSIBLE_ARGS) -i $(INVENTORY) --extra-vars @$(MASTER_CONFIG)
63ANSIBLE_PB_LOCAL ?= ansible-playbook $(ANSIBLE_ARGS) -i $(PI)/inventory/head-localhost --extra-vars "@/opt/cord_profile/genconfig/config.yml"
64ANSIBLE_PB_MAAS ?= ansible-playbook $(ANSIBLE_ARGS) -i /etc/maas/ansible/pod-inventory --extra-vars "@/opt/cord_profile/genconfig/config.yml"
65IMAGEBUILDER ?= python $(BUILD)/scripts/imagebuilder.py
66LOGCMD ?= 2>&1 | tee -a $(LOGS)/$(TS)_$(@F)
67SSH_HEAD ?= ssh $(HEADNODE)
68SSH_BUILD ?= ssh $(BUILDNODE)
69
70# default target, prints help
71.DEFAULT: help
72
73help:
74 @echo "Please specify a target (config, build, teardown, ...)"
75
76# Config file generation
77config: $(CONFIG_FILES)
78
79
80$(CONFIG_FILES):
81 ansible-playbook -i 'localhost,' --extra-vars="cord_podconfig='$(PODCONFIG_PATH)' genconfig_dir='$(GENCONFIG_D)' scenarios_dir='$(SCENARIOS_D)'" $(BUILD)/ansible/genconfig.yml $(LOGCMD)
82
83printconfig: config
84 @echo "Scenario: $(SCENARIO)"
85 @echo "Profile: $(PROFILE)"
86
87# Primary Targets
88# Many of these targets use target-specific variables
89# https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html
90
91build: $(BUILD_TARGETS)
92
93# Utility targets
94
95xos-teardown: xos-update-images
96 $(ANSIBLE_PB) $(PI)/teardown-playbook.yml $(LOGCMD)
97 rm -f $(M)/onboard-profile $(M)/local-onboard-profile
98
99xos-update-images: clean-images
100 rm -f $(M)/core-image $(M)/start-xos $(M)/local-core-image $(M)local-start-xos
101
102compute-node-refresh:
103 $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_MAAS) $(PI)/compute-node-refresh-playbook.yml" $(LOGCMD)
104
105vagrant-destroy:
106 $(VAGRANT) destroy $(LOGCMD)
107 rm -f $(M)/vagrant-up
108
109clean-images:
110 rm -f $(M)/docker-images $(M)/local-docker-images
111
112clean-genconfig:
113 rm -f $(CONFIG_FILES)
114
115clean-profile:
116 rm -rf $(CONFIG_CORD_PROFILE_DIR)
117 rm -f $(M)/cord-config $(M)/copy-config
118
119clean-all: vagrant-destroy clean-profile clean-genconfig
120 rm -f $(ALL_MILESTONES)
121
122clean-local: clean-profile clean-genconfig
123 rm -f $(LOCAL_MILESTONES)
124
125# == PREREQS == #
126VAGRANT_UP_PREREQS ?=
127CORD_CONFIG_PREREQS ?=
128COPY_CONFIG_PREREQS ?=
129PREP_BUILDNODE_PREREQS ?=
130PREP_HEADNODE_PREREQS ?=
131
132# == MILESTONES == #
133# empty target files are touched in the milestones dir to indicate completion
134
135$(M)/prereqs-check:
136 $(ANSIBLE_PB) $(PI)/prereqs-check-playbook.yml $(LOGCMD)
137 touch $@
138
139$(M)/vagrant-up: | $(VAGRANT_UP_PREREQS)
140 $(VAGRANT) up $(VAGRANT_VMS) --provider $(VAGRANT_PROVIDER) $(LOGCMD)
141 @echo "Configuring SSH for VM's..."
142 $(VAGRANT) ssh-config $(VAGRANT_VMS) > $(SSH_CONFIG)
143 touch $@
144
145$(M)/copy-cord: | $(M)/vagrant-up
146 $(ANSIBLE_PB) $(PI)/copy-cord-playbook.yml $(LOGCMD)
147 touch $@
148
149$(M)/cord-config: | $(M)/vagrant-up $(CORD_CONFIG_PREREQS)
150 $(ANSIBLE_PB) $(PI)/cord-config-playbook.yml $(LOGCMD)
151 cp -r $(GENCONFIG_D) $(CONFIG_CORD_PROFILE_DIR)/genconfig
152 touch $@
153
154$(M)/copy-config: | $(COPY_CONFIG_PREREQS)
155 $(ANSIBLE_PB) $(PI)/copy-profile-playbook.yml $(LOGCMD)
156 touch $@
157
158$(M)/prep-buildnode: | $(M)/vagrant-up $(M)/cord-config $(PREP_BUILDNODE_PREREQS)
159 $(ANSIBLE_PB) $(PI)/prep-buildnode-playbook.yml $(LOGCMD)
160 @echo Waiting 10 seconds to timeout SSH ControlPersist, and so future ansible commands gain docker group membership
161 sleep 10
162 touch $@
163
164$(M)/prep-headnode: | $(M)/vagrant-up $(M)/cord-config $(PREP_HEADNODE_PREREQS)
165 $(ANSIBLE_PB) $(PI)/prep-headnode-playbook.yml $(LOGCMD)
166 touch $@
167
168$(M)/elasticstack: | $(M)/prep-headnode
169 $(ANSIBLE_PB) $(PI)/deploy-elasticstack-playbook.yml $(LOGCMD)
170 touch $@
171
172$(M)/prep-computenode: | $(M)/prep-headnode
173 $(ANSIBLE_PB) $(PI)/prep-computenode-playbook.yml $(LOGCMD)
174 touch $@
175
176$(M)/glance-images: | $(M)/prep-headnode
177 $(ANSIBLE_PB) $(PI)/glance-images-playbook.yml $(LOGCMD)
178 touch $@
179
180$(M)/deploy-openstack: | $(M)/elasticstack $(M)/prep-headnode $(M)/prep-computenode
181 $(ANSIBLE_PB) $(PI)/deploy-openstack-playbook.yml $(LOGCMD)
182 touch $@
183
184$(M)/deploy-maas: | $(M)/deploy-openstack
185 $(ANSIBLE_PB) $(MAAS)/head.yml $(LOGCMD)
186 touch $@
187
188$(M)/deploy-computenode: | $(M)/deploy-openstack
189 $(ANSIBLE_PB) $(PI)/deploy-computenode-playbook.yml $(LOGCMD)
190 touch $@
191
192$(M)/docker-images: | $(M)/prep-buildnode
193 $(SSH_BUILD) "cd /opt/cord/build; $(IMAGEBUILDER) -f $(MASTER_CONFIG) -l $(BUILD)/image_logs -g $(BUILD)/ib_graph.dot -a $(BUILD)/ib_actions.yml " $(LOGCMD)
194 touch $@
195
196$(M)/core-image: | $(M)/docker-images $(M)/prep-headnode
197 $(ANSIBLE_PB) $(PI)/build-core-image-playbook.yml $(LOGCMD)
198 touch $@
199
200$(M)/start-xos: | $(M)/prep-headnode $(M)/core-image
201 $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/start-xos-playbook.yml" $(LOGCMD)
202 touch $@
203
204$(M)/onboard-profile: | $(M)/start-xos
205 $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/onboard-profile-playbook.yml" $(LOGCMD)
206 touch $@
207
208$(M)/deploy-onos: | $(M)/start-xos $(M)/docker-images
209 $(ANSIBLE_PB) $(PI)/deploy-onos-playbook.yml $(LOGCMD)
210 touch $@
211
212$(M)/onboard-openstack: | $(M)/deploy-computenode $(M)/glance-images $(M)/deploy-onos $(M)/onboard-profile
213 $(SSH_HEAD) "cd /opt/cord/build; $(ANSIBLE_PB_LOCAL) $(PI)/onboard-openstack-playbook.yml" $(LOGCMD)
214 touch $@
215
216# Testing targets
217pod-test: $(M)/onboard-openstack
218 $(ANSIBLE_PB) $(PI)/pod-test-playbook.yml $(LOGCMD)
219
220# Local Targets, bring up XOS containers without a VM
221
222$(M)/local-cord-config:
223 $(ANSIBLE_PB) $(PI)/cord-config-playbook.yml $(LOGCMD)
224 touch $@
225
226$(M)/local-docker-images: | $(M)/local-cord-config
227 $(IMAGEBUILDER) -f $(MASTER_CONFIG) -l $(BUILD)/image_logs -g $(BUILD)/ib_graph.dot -a $(BUILD)/ib_actions.yml $(LOGCMD)
228 touch $@
229
230$(M)/local-core-image: | $(M)/local-docker-images
231 $(ANSIBLE_PB) $(PI)/build-core-image-playbook.yml $(LOGCMD)
232 touch $@
233
234$(M)/local-start-xos: | $(M)/local-core-image
235 $(ANSIBLE_PB) $(PI)/start-xos-playbook.yml $(LOGCMD)
236 touch $@
237
238$(M)/local-onboard-profile: | $(M)/local-start-xos
239 $(ANSIBLE_PB) $(PI)/onboard-profile-playbook.yml $(LOGCMD)
240 touch $@
241