Custom Search

Wednesday, November 30, 2016

org.apache.cassandra.exceptions.ConfigurationException: Saved cluster name Test Cluster != configured name

Error:
ERROR [main] 2016-11-29 09:25:57,971 CassandraDaemon.java:296 - Fatal exception during initialization
org.apache.cassandra.exceptions.ConfigurationException: Saved cluster name Test Cluster != configured name my-cluster
        at org.apache.cassandra.db.SystemKeyspace.checkHealth(SystemKeyspace.java:613) ~[apache-cassandra-2.1.16.jar:2.1.16]
        at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:292) [apache-cassandra-2.1.16.jar:2.1.16]
        at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:566) [apache-cassandra-2.1.16.jar:2.1.16]
        at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:655) [apache-cassandra-2.1.16.jar:2.1.16]

Fix:
$ sudo rm -rf /var/lib/cassandra/data/system/*
$ sudo service cassandra restart


python django AttributeError: 'User' object has no attribute 'userprofile_set'

Error:
request.user.userprofile_set
AttributeError: 'User' object has no attribute 'get_profile'

Fix:
a)
Remove 
AUTH_PROFILE_MODULE = "core.userprofile"
from settings.py

b)
Change "ForeignKey" to "OneToOneField"
Then add keyword arg related_name='profile'
class UserProfile(models.Model):  
    user = models.ForeignKey(User, unique=True)
To
class UserProfile(models.Model):  
    user = models.OneToOneField(User, unique=True, related_name='profile')

c)
Change
request.user.userprofile_set.all()
To
request.user.profile

python django AttributeError: 'User' object has no attribute 'get_profile'

Error:
request.user.get_profile()
AttributeError: 'User' object has no attribute 'get_profile'

Fix:
a)
Remove 
AUTH_PROFILE_MODULE = "core.userprofile"
from settings.py

b)
Change "ForeignKey" to "OneToOneField"
Then add keyword arg related_name='profile'
class UserProfile(models.Model):  
    user = models.ForeignKey(User, unique=True)
To
class UserProfile(models.Model):  
    user = models.OneToOneField(User, unique=True, related_name='profile')

c)
Change
request.user.get_profile()
To
request.user.profile


python django AttributeError: 'module' object has no attribute 'commit_manually'

Error:
@transaction.commit_manually
AttributeError: 'module' object has no attribute 'commit_manually'

Fix:
def disable_auto_commit(func):
    def wrapper(*args, **kwargs):
        transaction.set_autocommit(False)
        return func(*args, **kwargs)
    return wrapper


@disable_auto_commit
def my_view(request):
       .... .....
      ..... .....



python django AttributeError: 'module' object has no attribute 'commit_on_success'

Error:
from django.db import connection, transaction
@transaction.commit_on_success
AttributeError: 'module' object has no attribute 'commit_on_success'

Fix:
@transaction.commit_on_success has been deprecated in Django 1.6, use
@transaction.atomic() decorator instead of @transaction.commit_on_success

python django ImportError: No module named defaults

Error:
from django.conf.urls.defaults import *
ImportError: No module named defaults

Fix:
from django.conf.urls.defaults has been removed in latest version of django

Use following import statements
from django.conf.urls import *
from django.conf.urls import patterns, url, include



There is no South database module 'south.db.postgresql_psycopg2' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS

Error:
There is no South database module 'south.db.postgresql_psycopg2' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS

Fix:
a)
In settings.py, remove South from INSTALLED_APPS

INSTALLED_APPS = [
'south'
]

b)
Uninstall south
$pip uninstall south


python django ImportError: cannot import name simplejson

Error:
from django.utils import simplejson
ImportError: cannot import name simplejson

Fix:
Use json module
import json as simplejson


python django ImportError: cannot import name update_wrapper

Error:
from django.utils.functional import update_wrapper
ImportError: cannot import name update_wrapper

Fix:
import update_wrapper from functools
from functools import update_wrapper

python django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form BuildingAdminForm needs updating.

Error:
python django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form BuildingAdminForm needs updating.

Fix:
Add fields = "__all__" inn Meta class of your model form
class MyAdminForm(forms.ModelForm):
    class Meta:
        model = MyModel
        fields = "__all__"


python django ImportError: cannot import name email_re

Error:
from django.core.validators import email_re
ImportError: cannot import name email_re

Fix:
Use validate_email function
from django.core.validators import validate_email

python django ImportError: cannot import name find_template

Error:
from django.template.loader import find_template
ImportError: cannot import name find_template

Fix:
Use get_template
from django.template.loader import get_template

python django ImportError: cannot import name execute_manager

Error:
python django ImportError: cannot import name execute_manager

Fix:
a)
Remove following lines from manage.py 
from django.core.management import execute_manager

b)
Then add following lines from manage.py 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)



python django ImportError: No module named localflavor.us.models

Error:
ImportError: No module named localflavor.us.models

Fix:
a)
$ pip install django-localflavor

b)
In settings.py, add "localflavor" in INSTALLED_APPS

c)
Then change the import statement, like
from localflavor.us.models import PhoneNumberField

python django AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

Error:
AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

Fix:
Make following change in your app's app.wsgi file

Delete/Comment out Following lines from wsgi file
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

Then add Following lines to wsgi file
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()




Tuesday, November 8, 2016

How to install specific Ubuntu packages with exact version

1)
$ sudo apt-cache policy python-neutron
python-neutron:
  Installed: 2015.1.3.dev74+1
  Candidate: 2015.1.3.dev74+1
  Version table:
     1:2015.1.2-0ubuntu2~cloud0 0
        700 http://11.11.11.9/snapshots/5b1646b3-6124-4e6b-a42b-e1af7428c5d9/ubuntu-cloud.archive.canonical.com/ubuntu/ trusty-updates/kilo/main amd64 Packages

2)
$ sudo apt-get install python-neutron=1:2015.1.2-0ubuntu2~cloud0


How to create a PEM file for HAProxy Configure SSL Certificate

1)
Generate a unique private key (KEY)
$sudo openssl genrsa -out mydomain.key 2048

Note:
Content in this file start with -----BEGIN RSA PRIVATE KEY-----

2)
Generating a Certificate Signing Request (CSR)
$sudo openssl req -new -key mydomain.key -out mydomain.csr

Note:
Content in this file start with -----BEGIN CERTIFICATE REQUEST-----



3)
Creating a Self-Signed Certificate (CRT)
$openssl x509 -req -days 365 -in mydomain.csr -signkey mydomain.key -out mydomain.crt

Note:
Content in this file start with -----BEGIN CERTIFICATE-----

4)
Append KEY and CRT to mydomain.pem
$sudo bash -c 'cat mydomain.key mydomain.crt >> /etc/ssl/private/mydomain.pem'

Note:
This pem file contains 2 sections (certificates), one start with -----BEGIN RSA PRIVATE KEY----- and  another one start with -----BEGIN CERTIFICATE-----

5)
Specify PEM in haproxy config
$ sudo vim /etc/haproxy/haproxy.cfg
listen haproxy
  bind 0.0.0.0:443 ssl crt /etc/ssl/private/mydomain.pem
  mode  http
  option http-server-close
  option forwardfor
  reqadd X-Forwarded-Proto:\ https
  reqadd X-Forwarded-Port:\ 443
  option forwardfor if-none
  balance  roundrobin
  option  abortonclose
  server 192.168.100.224 192.168.100.224:1443 check inter 10s rise 2 fall 3 ssl verify none

6)
Restart haproxy
$ sudo service haproxy restart

Ref:
https://gist.github.com/sethwebster/b48d7c872fe397c1db11
https://help.ubuntu.com/lts/serverguide/certificates-and-security.html