Custom Search
Showing posts with label tacker. Show all posts
Showing posts with label tacker. Show all posts

Thursday, August 25, 2016

openstack tacker how to run unittest

$ python -m testtools.run tackerclient.tests.unit.test_validators.ValidatorTest.test_validate_file_size
$ python -m testtools.run tackerclient.tests.unit.vm.test_cli10_vnf

$ sudo tox -epy27

Friday, August 5, 2016

openstack tacker toscaparser and hot tosca_translator example

import toscaparser
from toscaparser.utils import yamlparser
from toscaparser.tosca_template import ToscaTemplate
from translator.hot.tosca_translator import TOSCATranslator
from tacker.vm.tosca import utils as toscautils

vnfd_yaml = open("sample.yaml")
vnfd_dict = yamlparser.simple_ordered_parse(vnfd_yaml)

toscautils.updateimports(vnfd_dict)

tosca = ToscaTemplate(yaml_dict_tpl=vnfd_dict)


monitoring_dict = toscautils.get_vdu_monitoring(tosca)
mgmt_ports = toscautils.get_mgmt_ports(tosca)
res_tpl = toscautils.get_resources_dict(tosca)

toscautils.post_process_template(tosca)


translate = TOSCATranslator(tosca, {})
heat_template_yaml = translate.translate()


heat_template_yaml = toscautils.post_process_heat_template(heat_template_yaml, mgmt_ports, res_tpl)

print heat_template_yaml


Thursday, July 14, 2016

How to tacker-db-manage generate database migration script and test upgrade and downgrade

a)
First add new column to "Vim" model.

$tacker/db/nfvo/nfvo_db.py

class Vim(model_base.BASE, models_v1.HasId, models_v1.HasTenant):
    type = sa.Column(sa.String(64), nullable=False)
    name = sa.Column(sa.String(255), nullable=False)
    description = sa.Column(sa.Text, nullable=True)
    placement_attr = sa.Column(types.Json, nullable=True)
    shared = sa.Column(sa.Boolean, default=True, server_default=sql.true(
    ), nullable=False)
    default = sa.Column(sa.Boolean, default=False, server_default=sql.false(
    ), nullable=False)
    vim_auth = orm.relationship('VimAuth')
    status = sa.Column(sa.String(255), nullable=False)

b)
Then Generate Migration script.
$ ls tacker/db/migration/alembic_migrations/versions/ | wc -l

* name of the migration script file taken from -m option
$ tacker-db-manage --config-file /etc/tacker/tacker.conf revision -m "add default to vim" --autogenerate

* Open auto generated  migration script.
$ vim tacker/db/migration/alembic_migrations/versions/d4f265e8eb9d_add_default_to_vim.py

* Then delete unwanted statements from "upgrade" and "downgrade" methods

c)
Test upgrade and downgrade:

$ tacker-db-manage --config-file /etc/tacker/tacker.conf check_migration

$ tacker-db-manage --config-file /etc/tacker/tacker.conf history
2f2e337fc6c4 -> d4f265e8eb9d (head), add default to vim

$ tacker-db-manage --config-file /etc/tacker/tacker.conf current
2f2e337fc6c4

* Upgrade to head
$ tacker-db-manage --config-file /etc/tacker/tacker.conf upgrade head
INFO  [alembic.runtime.migration] Running upgrade 2f2e337fc6c4 -> d4f265e8eb9d, add default to vim

$ tacker-db-manage --config-file /etc/tacker/tacker.conf current
d4f265e8eb9d (head)

* Downgrade to 2f2e337fc6c4
$ tacker-db-manage --config-file /etc/tacker/tacker.conf downgrade 2f2e337fc6c4
INFO  [alembic.runtime.migration] Running downgrade d4f265e8eb9d -> 2f2e337fc6c4, add default to vim

$ tacker-db-manage --config-file /etc/tacker/tacker.conf current
2f2e337fc6c4


Tuesday, July 12, 2016

How to use tacker-db-manage to migrate database

1)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf history
5f88e86b35c7 -> 22f5385a3d3f (head), Add status to vims
354de64ba129 -> 5f88e86b35c7, make VNFD/VNF/VIM name mandatory
b07673bb8654 -> 354de64ba129, set-mandatory-columns-not-null
c7cde2f45f82 -> b07673bb8654, set-status-type-tenant-id-length
6e56d4474b2a -> c7cde2f45f82, set-description-to-text
f958f58e5daa -> 6e56d4474b2a, blob-to-json-text
acf941e54075 -> f958f58e5daa, uuid consistency
5246a6bd410f -> acf941e54075, Add error_reason to device
24bec5f211c7 -> 5246a6bd410f, multisite_vim
2774a42c7163 -> 24bec5f211c7, Alter value in deviceattributes
12a57080b278 -> 2774a42c7163, remove service related
12a57080b277 -> 12a57080b278, Alter devices
5958429bcb3c -> 12a57080b277, Add Service related dbs
13c0e0661015 -> 5958429bcb3c, modify datatype of value
4c31092895b8 -> 13c0e0661015, add descrition to vnf
81ffa86020d -> 4c31092895b8, empty message
1c6b0d82afcd -> 81ffa86020d, rpc_proxy
-> 1c6b0d82afcd, add tables for tacker framework

2)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf current
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
5f88e86b35c7

3)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf revision
  Generating /opt/stack/tacker/tacker/db/migration/alembic_migrations/versions/2f2e337fc6c4_.py ... done

4)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf upgrade 2f2e337fc6c4
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 5f88e86b35c7 -> 22f5385a3d3f, Add status to vims
INFO  [alembic.runtime.migration] Running upgrade 22f5385a3d3f -> 2f2e337fc6c4, empty message

5)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf history
22f5385a3d3f -> 2f2e337fc6c4 (head), empty message
5f88e86b35c7 -> 22f5385a3d3f, Add status to vims
354de64ba129 -> 5f88e86b35c7, make VNFD/VNF/VIM name mandatory
b07673bb8654 -> 354de64ba129, set-mandatory-columns-not-null
c7cde2f45f82 -> b07673bb8654, set-status-type-tenant-id-length
6e56d4474b2a -> c7cde2f45f82, set-description-to-text
f958f58e5daa -> 6e56d4474b2a, blob-to-json-text
acf941e54075 -> f958f58e5daa, uuid consistency
5246a6bd410f -> acf941e54075, Add error_reason to device
24bec5f211c7 -> 5246a6bd410f, multisite_vim
2774a42c7163 -> 24bec5f211c7, Alter value in deviceattributes
12a57080b278 -> 2774a42c7163, remove service related
12a57080b277 -> 12a57080b278, Alter devices
5958429bcb3c -> 12a57080b277, Add Service related dbs
13c0e0661015 -> 5958429bcb3c, modify datatype of value
4c31092895b8 -> 13c0e0661015, add descrition to vnf
81ffa86020d -> 4c31092895b8, empty message
1c6b0d82afcd -> 81ffa86020d, rpc_proxy
-> 1c6b0d82afcd, add tables for tacker framework

6)
$ tacker-db-manage --config-file /etc/tacker/tacker.conf current
INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
2f2e337fc6c4 (head)

========================
1)
Migrate to head
$ tacker-db-manage --config-file /etc/tacker/tacker.conf upgrade head






Sunday, June 26, 2016

port forwarding with iptables to access horizon running in vagrant VM which run in remote baremetal node

$ sudo sysctl net.ipv4.ip_forward=1
$ sudo iptables -t nat -L
$ sudo iptables -t nat -A PREROUTING -p tcp -d 10.140.15.64 --dport 8081 -j DNAT --to-destination 192.168.56.20:80
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE


* Replace -A with -D to delete the rule.
* Run this commands in baremetal node "10.140.15.64".
* 10.140.15.64 === IP of baremetal node where vagrant with virtualbox is running.
* 192.168.56.20 === Hostonly adapter IP of virtualbox VM running on baremetal node
* We can access horizon running in 192.168.56.20 from our laptop like http://10.140.15.64:8081/dashboard

1)
Example:


a)
Check IP Forwarding in bare-metal node:

$ sudo sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

b)
Enable IP Forwarding 
in bare-metal node:
$ sudo sysctl net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1

c)
Check rules 
in bare-metal node:
$ sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination        

Chain INPUT (policy ACCEPT)
target     prot opt source               destination        

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

b)
Add your forwarding rule in
 bare-metal node:
$ sudo iptables -t nat -A PREROUTING -p tcp -d 10.140.15.64 --dport 8081 -j DNAT --to-destination 192.168.56.20:80

Tips:
* add multiple hostonly interfaces to Virtualbox VM and use one of the interface's IP which we can ping from bare-metal as destination IP in iptables rule.

e)
Check rules 
in bare-metal node:
$ sudo iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination        
DNAT       tcp  --  anywhere             10.140.15.64         tcp dpt:tproxy to:192.168.56.20:80

Chain INPUT (policy ACCEPT)
target     prot opt source               destination        

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

f)
Ask IPtables to Masquerade 
in bare-metal node:
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE

g)
Check rules 
in bare-metal node:
$ sudo iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination        
DNAT       tcp  --  anywhere             10.140.15.64         tcp dpt:tproxy to:192.168.56.20:80

Chain INPUT (policy ACCEPT)
target     prot opt source               destination        

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination        

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination        
MASQUERADE  all  --  anywhere             anywhere

h)
Access web service running in the VM from laptop.

http://10.140.15.64:8081/