Merge "Update APPC CSIT to support ccsdk changes"
[integration.git] / bootstrap / vagrant-onap / Vagrantfile
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
3
4
5 configuration = {
6   # Generic parameters used across all ONAP components
7   'public_net_id'       => '00000000-0000-0000-0000-000000000000',
8   'key_name'            => 'ecomp_key',
9   'pub_key'             => '',
10   'nexus_repo'          => 'https://nexus.onap.org/content/sites/raw',
11   'nexus_docker_repo'   => 'nexus3.onap.org:10001',
12   'nexus_username'      => 'docker',
13   'nexus_password'      => 'docker',
14   'dmaap_topic'         => 'AUTO',
15   'artifacts_version'   => '1.0.0',
16   'docker_version'      => '1.0-STAGING-latest',
17   'gerrit_branch'       => 'master',
18 # Parameters for DCAE instantiation
19   'dcae_zone'           => 'iad4',
20   'dcae_state'          => 'vi',
21   'openstack_tenant_id' => '',
22   'openstack_username'  => '',
23   'openstack_api_key'   => '',
24   'openstack_password'  => '',
25   'nexus_repo_root'     => 'https://nexus.onap.org',
26   'nexus_url_snapshot'  => 'https://nexus.onap.org/content/repositories/snapshots',
27   'gitlab_branch'       => 'master',
28   'build_image'         => 'True',
29   'pull_docker_image'   => 'True',
30   'odl_version'         => '0.5.3-Boron-SR3',
31   'clone_repo'          => 'True',
32   'compile_repo'        => 'False',
33   'enable_oparent'      => 'True'
34 }
35
36
37 box = {
38   :virtualbox => 'ubuntu/trusty64',
39   :libvirt => 'sputnik13/trusty64',
40   :openstack => nil
41 }
42
43
44 nodes = [
45     { 
46     :name   => "aai",
47     :ips    => ['10.252.0.6', "192.168.50.6"],
48     :macs   => [],
49     :cpus   => 2,
50     :cpu    => "50",
51     :ram    => 4 * 1024,
52     :groups => ["individual"],
53     :args   => ["aai"]
54   },
55   { 
56     :name   => "all-in-one",
57     :ips    => ['10.252.0.3', "192.168.50.3"],
58     :macs   => [],
59     :cpus   => 2,
60     :cpu    => "50",
61     :ram    => 12 * 1024,
62     :groups => ["all-in-one"],
63     :flavor => 'm1.xlarge',
64     :args   => ['mr', 'sdc', 'aai', 'mso', 'robot', 'vid', 'sdnc', 'portal', 'dcae', 'policy', 'appc', 'vfc', 'ccsdk'],
65   },
66   { 
67     :name   => "appc",
68     :ips    => ['10.252.0.14', "192.168.50.14"],
69     :macs   => [],
70     :cpus   => 2,
71     :cpu    => "50",
72     :ram    => 4 * 1024,
73     :groups => ["individual"],
74     :args   => ["appc"],
75   },
76   { 
77     :name   => "ccsdk",
78     :ips    => ['10.252.0.14', "192.168.50.17"],
79     :macs   => [],
80     :cpus   => 2,
81     :cpu    => "50",
82     :ram    => 4 * 1024,
83     :groups => ["individual"],
84     :args   => ["ccsdk"],
85   },
86   { 
87     :name   => "dcae",
88     :ips    => ['10.252.0.12', "192.168.50.12"],
89     :macs   => [],
90     :cpus   => 2,
91     :cpu    => "50",
92     :ram    => 4 * 1024,
93     :groups => ["individual"],
94     :args   => ["dcae"],
95   },
96   { 
97     :name   => "dns",
98     :ips    => ['10.252.0.3', "192.168.50.3"],
99     :macs   => [],
100     :cpus   => 2,
101     :cpu    => "50",
102     :ram    => 1 * 1024,
103     :groups => ["individual"],
104     :flavor => 'm1.small',
105     :args   => [" "]
106   },
107   { 
108     :name   => "message-router",
109     :ips    => ['10.252.0.4', "192.168.50.4"],
110     :macs   => [],
111     :cpus   => 2,
112     :cpu    => "50",
113     :ram    => 4 * 1024,
114     :groups => ["individual"],
115     :args   => ["mr"],
116   },
117   { 
118     :name   => "mso",
119     :ips    => ['10.252.0.7', "192.168.50.7"],
120     :macs   => [],
121     :cpus   => 2,
122     :cpu    => "50",
123     :ram    => 4 * 1024,
124     :groups => ["individual"],
125     :args   => ["mso"],
126   },
127   { 
128     :name   => "multicloud",
129     :ips    => ['10.252.0.16', "192.168.50.16"],
130     :macs   => [],
131     :cpus   => 2,
132     :cpu    => "50",
133     :ram    => 4 * 1024,
134     :groups => ["individual"],
135     :args   => ["multicloud"],
136   },
137   { 
138     :name   => "policy",
139     :ips    => ['10.252.0.13', "192.168.50.13"],
140     :macs   => [],
141     :cpus   => 2,
142     :cpu    => "50",
143     :ram    => 4 * 1024,
144     :groups => ["individual"],
145     :args   => ["policy"],
146   },
147   { 
148     :name   => "portal",
149     :ips    => ['10.252.0.11', "192.168.50.11"],
150     :macs   => [],
151     :cpus   => 2,
152     :cpu    => "50",
153     :ram    => 4 * 1024,
154     :groups => ["individual"],
155     :args   => ["portal"],
156   },
157   { 
158     :name   => "robot",
159     :ips    => ['10.252.0.8', "192.168.50.8"],
160     :macs   => [],
161     :cpus   => 2,
162     :cpu    => "50",
163     :ram    => 4 * 1024,
164     :groups => ["individual"],
165     :args   => ["robot"],
166   },
167   { 
168     :name   => "sdc",
169     :ips    => ['10.252.0.5', "192.168.50.5"],
170     :macs   => [],
171     :cpus   => 2,
172     :cpu    => "50",
173     :ram    => 8 * 1024,
174     :groups => ["individual"],
175     :args   => ["sdc"],
176   },
177   { 
178     :name   => "sdnc",
179     :ips    => ['10.252.0.10', "192.168.50.10"],
180     :macs   => [],
181     :cpus   => 2,
182     :cpu    => "50",
183     :ram    => 4 * 1024,
184     :groups => ["individual"],
185     :args   => ["sdnc"],    
186   },
187   { 
188     :name   => "testing",
189     :ips    => ['10.252.0.3', "192.168.50.3"],
190     :macs   => [],
191     :cpus   => 2,
192     :cpu    => "50",
193     :ram    => 4 * 1024,
194     :groups => ["testing"],
195     :flavor => 'm1.small',
196     :args   => [""],
197   },
198   { 
199     :name   => "vfc",
200     :ips    => ['10.252.0.15', "192.168.50.15"],
201     :macs   => [],
202     :cpus   => 2,
203     :cpu    => "50",
204     :ram    => 4 * 1024,
205     :groups => ["individual"],
206     :args   => ['vfc'],
207   },
208   
209   { 
210     :name   => "vid",
211     :ips    => ['10.252.0.9', "192.168.50.9"],
212     :macs   => [],
213     :cpus   => 2,
214     :cpu    => "50",
215     :ram    => 4 * 1024,
216     :groups => ["individual"],
217     :args   => ['vid'],
218   }, 
219 ]
220
221
222 run_path = 'vagrant_utils/postinstall.sh'
223
224 sdc_volume='vol1-sdc-data.vdi'
225
226 Vagrant.require_version ">= 1.8.6"
227
228 # Determine the provider used
229 provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
230 puts "[INFO] Provider: #{provider} "
231
232
233 vd_conf = ENV.fetch('VD_CONF', 'etc/settings.yaml')
234 if File.exist?(vd_conf)
235   require 'yaml'
236   user_conf = YAML.load_file(vd_conf)
237   configuration.update(user_conf)
238 end
239
240 #Set network interface
241 is_windows = Gem.win_platform?
242 if is_windows
243     net_interface = 'VirtualBox Host-Only Ethernet Adapter #2'
244 else
245     net_interface = 'vboxnet0'
246 end
247 puts "[INFO] Net interface: #{net_interface}"
248
249
250 #If argument is given use it. Otherwise use Env: DEPLOY_MODE else use default
251 requested_machine = ARGV[1]
252
253 deploy_mode = ENV.fetch('DEPLOY_MODE', 'individual')
254 if requested_machine != nil
255     if requested_machine.include?("all-in-one") || requested_machine.include?("testing")
256         deploy_mode = requested_machine
257     end
258 end
259
260 #Catch the status of all machines
261 if ARGV[0] == 'status' || ARGV[0] == 'destroy'
262     deploy_mode = 'NA'
263 end
264
265 puts "[INFO] Deploy Mode:  #{deploy_mode}"
266
267 #In case of all-in-one or testing clean the nodes list
268 case deploy_mode
269     when 'all-in-one'
270         nodes.select! do |node|
271             if node[:name].include?("all-in-one")
272               true if node[:name]
273             end
274         end
275
276     when 'individual'
277         nodes.select! do |node|
278             if node[:groups][0].include?("individual")
279               true if node[:name]
280                
281             end
282         end
283
284     when 'testing'
285         nodes.select! do |node|
286             if node[:name].include?("testing")
287               true if node[:name]
288             end
289         end
290 end
291
292 Vagrant.configure("2") do |config|
293
294   # PROXY definitions
295     if ENV['http_proxy'] != nil and ENV['https_proxy'] != nil and ENV['no_proxy'] != nil
296       if not Vagrant.has_plugin?('vagrant-proxyconf')
297         system 'vagrant plugin install vagrant-proxyconf'
298         raise 'vagrant-proxyconf was installed but it requires to execute again'
299       end
300       config.proxy.http     = ENV['http_proxy']
301       config.proxy.https    = ENV['https_proxy']
302       config.proxy.no_proxy = ENV['no_proxy']
303     end
304
305     if Vagrant.has_plugin?('vagrant-vbguest')
306       puts 'vagrant-vbguest auto_update feature will be disable to avoid sharing conflicts'
307       config.vbguest.auto_update = false
308     end
309
310     if provider == :libvirt
311       if not Vagrant.has_plugin?('vagrant-libvirt')
312         system 'vagrant plugin install vagrant-libvirt'
313         raise 'vagrant-libvirt was installed but it requires to execute again'
314       end
315     end
316     if provider == :openstack
317       config.ssh.username = 'ubuntu'
318       if not Vagrant.has_plugin?('vagrant-openstack-provider')
319         system 'vagrant plugin install vagrant-openstack-provider'
320         raise 'vagrant-openstack-provider was installed but it requires to execute again'
321       end
322     end
323
324     nodes.each do |node|
325       config.vm.define node[:name] do |nodeconfig|
326
327         # Common Settings:
328         
329         nodeconfig.vm.provider "virtualbox" do |vbox|
330           vbox.customize ['modifyvm', :id, '--nictype1', 'virtio']
331           vbox.customize ['modifyvm', :id, '--audio', 'none']
332           vbox.customize ['modifyvm', :id, '--vram', '1']
333           vbox.customize ['modifyvm', :id, "--cpuhotplug", "off"]
334           vbox.customize ['modifyvm', :id, "--cpuexecutioncap", node[:cpu]]
335           vbox.customize ['modifyvm', :id, "--cpus", node[:cpus]]  
336           vbox.customize ["modifyvm", :id, "--memory", node[:ram]]
337         end
338         
339         nodeconfig.vm.provider "libvirt" do |lbox|
340           lbox.memory = node[:ram]
341           lbox.nested = true
342         end
343         
344         nodeconfig.vm.provider :openstack do |obox|
345           obox.openstack_auth_url               = ENV.fetch('OS_AUTH_URL', '')
346           obox.tenant_name                      = ENV.fetch('OS_TENANT_NAME', '')
347           obox.username                         = ENV.fetch('OS_USERNAME', '')
348           obox.password                         = ENV.fetch('OS_PASSWORD', '')
349           obox.region                           = ENV.fetch('OS_REGION_NAME', '')
350           obox.identity_api_version             = ENV.fetch('OS_IDENTITY_API_VERSION', '')
351           obox.domain_name                      = ENV.fetch('OS_PROJECT_DOMAIN_ID', '')
352           obox.project_name                     = ENV.fetch('OS_PROJECT_NAME', '')
353           obox.floating_ip_pool                 = ENV.fetch('OS_FLOATING_IP_POOL', '')
354           obox.floating_ip_pool_always_allocate = (ENV['OS_FLOATING_IP_ALWAYS_ALLOCATE'] == 'true')
355           obox.image                            = ENV.fetch('OS_IMAGE', '')
356           obox.security_groups                  = [ENV.fetch('OS_SEC_GROUP', '')]
357           obox.networks                         = ENV.fetch('OS_NETWORK', '')
358           obox.flavor                           = node[:flavor]
359           obox.server_name                      = node[:name]
360
361         end
362
363         # Set Box type
364         nodeconfig.vm.box = box[provider]
365         
366         # Set Node name
367         nodeconfig.vm.hostname = node[:name]
368         
369         # Set Sync Folder
370         nodeconfig.vm.synced_folder ".", "/vagrant", disabled: true
371         nodeconfig.vm.synced_folder './opt', '/opt/', create: true
372         nodeconfig.vm.synced_folder './lib', '/var/onap/', create: true
373         if !is_windows
374           nodeconfig.vm.synced_folder '~/.m2', '/root/.m2/', create: true
375         end
376         # Set Network 
377         nodeconfig.vm.network :private_network, ip: node[:ips][1]
378
379         # Specific settings:
380         
381         #Set Storage (For SDC or All-in-one)
382         if node[:name].include?("all-in-one") || node[:name].include?("sdc")
383           nodeconfig.vm.provider "virtualbox" do |v|
384               unless File.exist?(sdc_volume)
385                   v.customize ['createhd', '--filename', sdc_volume, '--size', 20 * 1024]
386               end
387               v.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', sdc_volume]
388             end
389             
390             nodeconfig.vm.provider "libvirt" do |v|
391                 v.storage :file, path: sdc_volume, bus: 'sata', device: 'vdb', size: '2G'
392             end
393         end
394         
395         
396         if node[:name].include? "testing"
397             nodeconfig.vm.synced_folder './tests', '/var/onap_tests/', create: true
398             test_suite = ENV.fetch('TEST_SUITE', '*')
399             test_case = ENV.fetch('TEST_CASE', '*')
400             # Override variables
401             run_path = 'vagrant_utils/unit_testing.sh'
402             node[:args] = [test_suite, test_case]
403         end
404
405
406         if node[:name].include? "vfc"
407           nodeconfig.vm.provision 'docker'
408         end
409
410         nodeconfig.vm.provision 'shell' do |s|
411           s.path = run_path
412           s.args = node[:args]
413           s.env  = configuration
414         end
415
416       end #nodeconfig
417     end #node
418 end #config
419