Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #137 from jbatalle/master
Browse files Browse the repository at this point in the history
0.11.1
  • Loading branch information
jbatalle authored Dec 20, 2016
2 parents 6e261df + 8372628 commit 835b149
Show file tree
Hide file tree
Showing 59 changed files with 1,450 additions and 2,523 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ tmp
**/puma.pid
**/puma.state
fluentd
ns-monitoring/db/*.sqlite3
ns-monitoring/db/tenor_*.sqlite3
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,5 @@ script:
- curl localhost:4000/
- curl localhost:4000/network-services
- curl localhost:4569/vnfs
- ./tenor_install.sh 6
- curl localhost:4000/network-services
- curl localhost:4000/vnfs
- curl localhost:4000/ns-instances
- cd $TRAVIS_BUILD_DIR && BUNDLE_GEMFILE=$TRAVIS_BUILD_DIR/Gemfile && bundle update --quiet
- rspec
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.11.1
- Fix NS Provisioning Hash.
- Updated Descriptor Samples.
- Updated Cassandra Driver to official.
- Fix deletion.

## 0.11.0
- Finished some missing tests.
- Netfloc support finished.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ In order to test TeNOR functionality, you can deploy a dummy NSD/VNFD located in
We provide several examples with different functionalities. The VNFD_validator contains the VNFD examples and the NSD_validator folders the associtated NSDs.
The provided examples are:
- vnfd-validator/assets/samples/2910_vnfd_example.json -> Basic VNFD using a clean Ubuntu Cloud Image.
- vnfd-validator/assets/samples/2911_vnfd_existing_image_id.json -> You can reuse an image already loaded in Openstack. Modify the IMAGE_ID field.
- vnfd-validator/assets/samples/2912_vnfd_existing_network_id.json -> You can reuse a network already created in Openstack. Modify the NETWORK_ID field.
- vnfd-validator/assets/samples/2913_vnfd_scaling.json -> You can see how scale out/in works with this example.
- vnfd-validator/assets/samples/2914_vnfd_two_vdus.json -> This VDU contains two VDUs (instances).
You can test it using the same commands shown before but chaning the file.
Expand Down
2 changes: 1 addition & 1 deletion hot-generator/routes/hot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class HotGenerator < Sinatra::Application
halt 400, 'Networks ID not found' if networks_id.nil?

security_group_id = provision_info['security_group_id']
halt 400, 'Security group ID not found' if security_group_id.nil?
#halt 400, 'Security group ID not found' if security_group_id.nil?

vdus_deployed_info = provision_info['vdus_deployed_info']
halt 400, 'VDUs info not found' if vdus_deployed_info.nil?
Expand Down
4 changes: 2 additions & 2 deletions ns-manager/routes/ns_provisioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NsProvisioner < TnovaManager
halt e.response.code, e.response.body
end

logger.info "INSTANTIATION INFO: " + instantiation_info.to_s
logger.info "Instantiating a new service: " + instantiation_info.to_s

pop_list = []
mapping_info = {}
Expand Down Expand Up @@ -93,7 +93,7 @@ class NsProvisioner < TnovaManager
logger.error e.response
halt e.response.code, e.response.body
end
logger.info "Instantiation correct."
logger.info "Instantiation in process..."
updateStatistics('ns_instantiated_requests')
return response.code, response.body
end
Expand Down
8 changes: 8 additions & 0 deletions ns-manager/routes/scaling.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class NsScaling< TnovaManager
end
logger.info response.code

updateStatistics('ns_scaling_out_requests')

return response.code, response.body
end

Expand All @@ -63,6 +65,8 @@ class NsScaling< TnovaManager
end
logger.info response.code

updateStatistics('ns_scaling_in_requests')

return response.code, response.body
end

Expand All @@ -78,6 +82,8 @@ class NsScaling< TnovaManager
provisioner, errors = ServiceConfigurationHelper.get_module('ns_provisioner')
halt 500, errors if errors

updateStatistics('SLA_breaches')

# Validate JSON format
auto_scale_info = JSON.parse(request.body.read)

Expand Down Expand Up @@ -121,6 +127,8 @@ class NsScaling< TnovaManager
halt e.response.code, e.response.body
end

updateStatistics('auto_scaling_request_executed')

logger.error "AutoScaling executed."
return response.code, response.body
end
Expand Down
12 changes: 6 additions & 6 deletions ns-manager/spec/scaling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def app
expect(response.status).to eq 200
end

it 'response body should be empty' do
expect(response.body).to be_empty
it 'response body should be a string' do
expect(response.body).to be_a String
end
end
end
Expand All @@ -86,8 +86,8 @@ def app
expect(response.status).to eq 200
end

it 'response body should be empty' do
expect(response.body).to be_empty
it 'response body should be a string' do
expect(response.body).to be_a String
end
end

Expand All @@ -98,8 +98,8 @@ def app
expect(response.status).to eq 200
end

it 'response body should be empty' do
expect(response.body).to be_empty
it 'response body should be a string' do
expect(response.body).to be_a String
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion ns-manager/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#scaling stub
stub_request(:get, 'http://localhost:4012/ns-instances/5825ce99c098a434c100000c').to_return(status: 200, body: File.read(File.join('spec', 'fixtures', 'ns_instance.json')))
stub_request(:post, 'http://localhost:4012/ns-instances/scaling/5825ce99c098a434c100000c/scale_out').to_return(status: 200, body: "")
stub_request(:post, 'http://localhost:4012/ns-instances/scaling/5825ce99c098a434c100000c/scale_in').to_return(status: 200, body: "")
stub_request(:post, 'http://localhost:4012/ns-instances/scaling/5825ce99c098a434c100000c/scale_in').to_return(status: 200, body: "Scaling done.")

#monitoring
stub_request(:get, 'http://localhost:4014/ns-monitoring/id/monitoring-data/?instance_type=ns').to_return(status: 200, body: File.read(File.join('spec', 'fixtures', 'ns_catalogue.json')))
Expand Down
2 changes: 1 addition & 1 deletion ns-monitoring-repository/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ group :doc do
gem 'yard'
end

gem 'cassandra-cql', '~>1.2.2'
gem 'cassandra-driver', '~>3.1.0'

gem 'sinatra-gkauth', '~>0.4.0', path: '../gems/sinatra-gkauth-gem'
gem 'fluent-logger-sinatra', '~>0.2.0', path: '../gems/fluent-logger-sinatra'
13 changes: 5 additions & 8 deletions ns-monitoring-repository/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require 'sinatra'
require 'sinatra/config_file'
require 'yaml'
require 'cassandra-cql'
require 'cassandra'

# Require the bundler gem and then call Bundler.require to load in all gems listed in Gemfile.
require 'bundler'
Expand All @@ -43,17 +43,14 @@

cassandra_config_file = File.join(BASEDIR, 'config', 'database.yml')
cassandra_config = YAML.load_file(cassandra_config_file)[env]
@db = CassandraCQL::Database.new("#{cassandra_config['host']}:9160", username: cassandra_config['username'], password: cassandra_config['password'])
@db.execute("USE #{cassandra_config['keyspace']}")
cluster = Cassandra.cluster(
hosts: [cassandra_config['host']]
)
@db = cluster.connect(cassandra_config['keyspace'])
set :db, @db
end

before do
cassandra_config_file = File.join(BASEDIR, 'config', 'database.yml')
cassandra_config = YAML.load_file(cassandra_config_file)[env]
@db = CassandraCQL::Database.new("#{cassandra_config['host']}:9160", username: cassandra_config['username'], password: cassandra_config['password'])
@db.execute("USE #{cassandra_config['keyspace']}")

# env['rack.logger'] = logger
end

Expand Down
15 changes: 8 additions & 7 deletions ns-monitoring-repository/routes/ns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ class NsMonitoringRepository < Sinatra::Application
# Returns all monitored data
get '/ns-monitoring/:instance_id/monitoring-data/' do
t = []

@db = settings.db
if params[:metric] && params[:start] && !params[:end]
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date >= #{params[:start]} ORDER BY metricname DESC LIMIT 2000").fetch { |row| t.push(row.to_hash) }
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date >= #{params[:start]} ORDER BY metricname DESC LIMIT 2000").each { |row| t.push(row.to_hash) }
elsif params[:metric] && params[:start] && params[:end]
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date >= #{params[:start]} AND date <= #{params[:end]} LIMIT 2000").fetch { |row| t.push(row.to_hash) }
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date >= #{params[:start]} AND date <= #{params[:end]} LIMIT 2000").each { |row| t.push(row.to_hash) }
elsif params[:metric] && params[:end]
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date <= #{params[:end]} ORDER BY metricname DESC LIMIT 2000").fetch { |row| t.push(row.to_hash) }
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' AND date <= #{params[:end]} ORDER BY metricname DESC LIMIT 2000").each { |row| t.push(row.to_hash) }
elsif params[:metric] && !params[:start]
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' LIMIT 2000").fetch { |row| t.push(row.to_hash) }
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' LIMIT 2000").each { |row| t.push(row.to_hash) }
else
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' LIMIT 2000").fetch { |row| t.push(row.to_hash) }
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' LIMIT 2000").each { |row| t.push(row.to_hash) }
end
return t.to_json
end
Expand All @@ -42,7 +42,8 @@ class NsMonitoringRepository < Sinatra::Application
# Returns last 100 values
get '/ns-monitoring/:instance_id/monitoring-data/last100/' do
t = []
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' ORDER BY metricname DESC LIMIT 100").fetch { |row| t.push(row.to_hash) }
@db = settings.db
@db.execute("SELECT metricName, date, unit, value FROM nsmonitoring WHERE instanceid='#{params[:instance_id]}' AND metricname='#{params[:metric]}' ORDER BY metricname DESC LIMIT 100").each { |row| t.push(row.to_hash) }
return t.to_json
end

Expand Down
6 changes: 3 additions & 3 deletions ns-monitoring/config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
development:
adapter: sqlite3
database: db/tnova_orchestrator_dev.sqlite3
database: db/tenor_dev.sqlite3

production:
adapter: sqlite3
database: db/tnova_orchestrator_dev.sqlite3
database: db/tenor.sqlite3

test:
adapter: sqlite3
database: db/tnova_orchestrator_dev.sqlite3
database: db/tenor_test.sqlite3
1 change: 0 additions & 1 deletion ns-provisioning/helpers/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
require_relative 'vim'
require_relative 'monitoring'
require_relative 'mapping'
require_relative 'pop'
require_relative 'hot'
require_relative 'utils'
require_relative 'instantiation'
Expand Down
14 changes: 8 additions & 6 deletions ns-provisioning/helpers/instantiation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ def create_authentication(instance, pop_info)
pop_auth['urls'] = pop_urls

# create credentials for pop_id
if pop_urls[:keystone].nil? || pop_urls[:heat].nil? # || pop_urls[:tenant].nil?
if pop_urls['keystone'].nil? || pop_urls['heat'].nil?
logger.error pop_urls['keystone']
logger.error pop_urls['heat']
return handleError(@instance, 'Internal error: Keystone and/or openstack urls missing.')
end

token = ''
keystone_url = pop_urls[:keystone]
keystone_url = pop_urls['keystone']
if @instance['project'].nil?
credentials, errors = authenticate(keystone_url, pop_info['tenant_name'], pop_info['user'], pop_info['password'])
logger.error errors if errors
Expand All @@ -64,7 +66,7 @@ def create_authentication(instance, pop_info)
pop_auth['token'] = token
else
# generate credentials
credentials, errors = generate_credentials(@instance, keystone_url, pop_urls, tenant_id, user_id, token)
credentials, errors = generate_credentials(@instance, pop_urls, tenant_id, user_id, token)
return 400, errors if errors
pop_auth = pop_auth.merge(credentials)
end
Expand Down Expand Up @@ -106,9 +108,9 @@ def instantiate_vnf(instance, nsd_id, vnf, slaInfo)
vim_id: pop_id,
auth: {
url: {
keystone: pop_urls[:keystone],
heat: pop_urls[:heat],
compute: pop_urls[:compute]
keystone: pop_urls['keystone'],
heat: pop_urls['heat'],
compute: pop_urls['compute']
},
tenant_id: pop_auth['tenant_id'],
token: pop_auth['token'],
Expand Down
8 changes: 4 additions & 4 deletions ns-provisioning/helpers/keystone/authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def authenticate(keystone_url, tenant_name, username, password)
{ tenant_id: tenant_id, user_id: user_id, token: token }
end

def generate_credentials(instance, keystone_url, popUrls, tenant_id, user_id, token)
keystone_version = URI(keystone_url).path.split('/').last
def generate_credentials(instance, pop_urls, tenant_id, user_id, token)
keystone_version = URI(pop_urls['keystone']).path.split('/').last
if keystone_version == 'v2.0'
credentials, errors = generate_v2_credentials(instance, popUrls, tenant_id, user_id, token)
credentials, errors = generate_v2_credentials(instance, pop_urls, tenant_id, user_id, token)
return 400, errors if errors
elsif keystone_version == 'v3'
credentials, errors = generate_v3_credentials(instance, popUrls, tenant_id, user_id, token)
credentials, errors = generate_v3_credentials(instance, pop_urls, tenant_id, user_id, token)
return 400, errors if errors
end
credentials
Expand Down
21 changes: 11 additions & 10 deletions ns-provisioning/helpers/keystone/keystone_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@
#
# @see NSProvisioner
module Authenticationv2Helper
def generate_v2_credentials(instance, popUrls, tenant_id, user_id, token)
def generate_v2_credentials(instance, pop_urls, tenant_id, user_id, token)
logger.info "Generating v2 credentials..."
@instance = instance
pop_auth = {}
begin
if settings.default_tenant
pop_auth['username'] = settings.default_user_name
pop_auth['tenant_name'] = settings.default_tenant_name
pop_auth['tenant_id'] = getTenantId(popUrls[:keystone], pop_auth['tenant_name'], token)
pop_auth['user_id'] = getUserId(popUrls[:keystone], pop_auth['username'], token)
pop_auth['tenant_id'] = getTenantId(pop_urls['keystone'], pop_auth['tenant_name'], token)
pop_auth['user_id'] = getUserId(pop_urls['keystone'], pop_auth['username'], token)
pop_auth['password'] = 'secretsecret'

if pop_auth['tenant_id'].nil? && pop_auth['user_id'].nil?
stack_url, tenant_id, user_id = create_user_and_project(popUrls[:heat], @instance['id'], pop_auth['tenant_name'], pop_auth['username'], pop_auth['password'], tenant_id, token)
stack_url, tenant_id, user_id = create_user_and_project(pop_urls['heat'], @instance['id'], pop_auth['tenant_name'], pop_auth['username'], pop_auth['password'], tenant_id, token)
pop_auth['tenant_id'] = tenant_id
pop_auth['user_id'] = user_id
else
pop_auth['tenant_id'] = createTenant(popUrls[:keystone], pop_auth['tenant_name'], token) if pop_auth['tenant_id'].nil?
pop_auth['tenant_id'] = createTenant(pop_urls['keystone'], pop_auth['tenant_name'], token) if pop_auth['tenant_id'].nil?
if pop_auth['user_id'].nil?
pop_auth['user_id'] = createUser(popUrls[:keystone], pop_auth['tenant_id'], pop_auth['username'], pop_auth['password'], token)
pop_auth['user_id'] = createUser(pop_urls['keystone'], pop_auth['tenant_id'], pop_auth['username'], pop_auth['password'], token)
else
unless settings.default_user_password.nil?
pop_auth['password'] = settings.default_user_password
Expand All @@ -47,7 +48,7 @@ def generate_v2_credentials(instance, popUrls, tenant_id, user_id, token)
pop_auth['tenant_name'] = 'tenor_tenant_' + @instance['id'].to_s
pop_auth['username'] = 'user_' + @instance['id'].to_s
pop_auth['password'] = 'secretsecret'
stack_url, tenant_id, user_id = create_user_and_project(popUrls[:heat], @instance['id'], 'tenor_tenant_' + @instance['id'].to_s, 'user_' + @instance['id'].to_s, 'secretsecret', tenant_id, token)
stack_url, tenant_id, user_id = create_user_and_project(pop_urls['heat'], @instance['id'], 'tenor_tenant_' + @instance['id'].to_s, 'user_' + @instance['id'].to_s, 'secretsecret', tenant_id, token)
pop_auth['tenant_id'] = tenant_id
pop_auth['user_id'] = user_id
pop_auth['stack_url'] = stack_url
Expand All @@ -62,10 +63,10 @@ def generate_v2_credentials(instance, popUrls, tenant_id, user_id, token)
end

logger.info 'Created user with admin role.'
putRoleAdmin(popUrls[:keystone], pop_auth['tenant_id'], pop_auth['user_id'], token)
putRoleAdmin(pop_urls['keystone'], pop_auth['tenant_id'], pop_auth['user_id'], token)

logger.info 'Authentication using new user credentials.'
pop_auth['token'], errors = authentication_v2_ids(popUrls[:keystone], pop_auth['tenant_id'], pop_auth['user_id'], pop_auth['password'])
pop_auth['token'], errors = authentication_v2_ids(pop_urls['keystone'], pop_auth['tenant_id'], pop_auth['user_id'], pop_auth['password'])
if errors || pop_auth['token'].nil?
logger.error errors if errors
error = 'Authentication failed.'
Expand All @@ -76,7 +77,7 @@ def generate_v2_credentials(instance, popUrls, tenant_id, user_id, token)
end

logger.info 'Configuring Security Groups'
pop_auth['security_group_id'] = configureSecurityGroups(popUrls[:compute], pop_auth['tenant_id'], pop_auth['token'])
pop_auth['security_group_id'] = configureSecurityGroups(pop_urls['compute'], pop_auth['tenant_id'], pop_auth['token'])

logger.info 'Tenant id: ' + pop_auth['tenant_id']
logger.info 'Username: ' + pop_auth['username']
Expand Down
Loading

0 comments on commit 835b149

Please sign in to comment.