/AirBnB_clone_v2

hbnb - AirBnB Clone - Phase # 1: python BaseModel class & web static

Primary LanguageHTML

AirBnB Clone Phase #1

: python BaseModel Class, unittests, python CLI, & web static

Description

Project attempts to clone the the AirBnB application and website, including the database, storage, RESTful API, Web Framework, and Front End.

Environment

  • OS: Ubuntu 14.04 LTS
  • language: Python 3.4.3
  • style: PEP 8 (v. 1.7.0)

Testing

unittest

This project uses python library, unittest to run tests on all python files. All unittests are in the ./tests directory with the command:

  • python3 -m unittest discover -v ./tests/

The bash script init_test.sh executes all these tests:

  • checks pep8 style

  • runs all unittests

  • runs all w3c_validator tests

  • cleans up all __pycache__ directories and the storage file, file.json

Usage:

$ ./dev/init_test.sh

CLI Interactive Tests

This project uses python library, cmd to run tests in an interactive command line interface. To begin tests with the CLI, run this script:

$ ./console.py
  • For a detailed description of all tests, run these commands inside the custom CLI:
$ ./console.py
(hbnb) help help
List available commands with "help" or detailed help with "help cmd".
(hbnb) help

Documented commands (type help <topic>):
========================================
Amenity    City  Place   State  airbnb  create   help  show
BaseModel  EOF   Review  User   all     destroy  quit  update

(hbnb) help User
class method with .function() syntax
        Usage: User.<command>(<id>)
(hbnb) help create
create: create [ARG]
        ARG = Class Name
        SYNOPSIS: Creates a new instance of the Class from given input ARG
        EXAMPLE: create City
                 City.create()
  • Tests in the CLI may also be executed with this syntax:

    • destroy: <class name>.destroy(<id>)

    • update: <class name>.update(<id>, <attribute name>, <attribute value>)

    • update with dictionary: <class name>.update(<id>, <dictionary representation>)

Continuous Integration

Uses Travis-CI to run all tests on all commits to the github repo

Authors

License

Public Domain, no copyright protection -setup_web_static.sh -pack_web_static.py -do_deploy_web_static.py -deploy_web_static.py 00-clean_web_static.py

Write a Bash script that sets up your web servers for the deployment of web_static. It must:

  • Install Nginx if it not already installed
  • Create the folder /data/ if it doesn't already exist
  • Create the folder /data/web_static/ if it doesn't already exist
  • Create the folder /data/web_static/releases/ if it doesn't already exist
  • Create the folder /data/web_static/shared/ if it doesn't already exist
  • Create the folder /data/web_static/releases/test/ if it doesn't already exist
  • Create a fake HTML file /data/web_static/releases/test/index.html (with simple content, to test your Nginx configuration)
  • Create a symbolic link /data/web_static/current linked to the /data/web_static/releases/test/ folder. If the symbolic link already exists, it should be deleted and recreated every time the script is ran.
  • Give ownership of the /data/ folder to the ubuntu user AND group (you can assume this user and group exist). This should be recursive; everything inside should be created/owned by this user/group.
  • Update the Nginx configuration to serve the content of /data/web_static/current/ to hbnb_static (ex: https://mydomainname.tech/hbnb_static). Don't forget to restart Nginx after updating the configuration:
    • Use alias inside your Nginx configuration
    • Tip

Your program should always exit successfully. Don't forget to run your script on both of your web servers.

Write a Fabric script that generates a .tgz archive from the contents of the web_static folder of your AirBnB Clone repo, using the function do_pack.

  • Prototype: def do_pack():
  • All files in the folder web_static must be added to the final archive
  • All archives must be stored in the folder versions (your function should create this folder if it doesn't exist)
  • The name of the archive created must be web_static_<year><month><day><hour><minute><second>.tgz
  • The function do_pack must return the archive path if the archive has been correctly generated. Otherwise, it should return None

Write a Fabric script (based on the file 1-pack_web_static.py) that distributes an archive to your web servers, using the function do_deploy:

  • Prototype: def do_deploy(archive_path):
  • Returns False if the file at the path archive_path doesn't exist
  • The script should take the following steps:
    • Upload the archive to the /tmp/ directory of the web server
    • Write a Fabric script (based on the file 2-do_deploy_web_static.py) that creates and distributes an archive to your web servers, using the function deploy:

      • Prototype: def deploy():
      • The script should take the following steps:
        • Call the do_pack() function and store the path of the created archive
        • Return False if no archive has been created
        • Call the do_deploy(archive_path) function, using the new path of the new archive
        • Return the return value of do_deploy
      • All remote commands must be executed on both of web your servers (using env.hosts = ['<IP web-01>', 'IP web-02'] variable in your script)

      In the following example, the SSH key and the username used for accessing to the server are passed in the command line. Of course, you could define them as Fabric environment variables (ex: env.user =...)

      Write a Fabric script (based on the file 3-deploy_web_static.py) that deletes out-of-date archives, using the function do_clean:

      • Prototype: def do_clean(number=0):
      • number is the number of the archives, including the most recent, to keep.
        • If number is 0 or 1, keep only the most recent version of your archive.
        • if number is 2, keep the most recent, and second most recent versions of your archive.
        • etc.
      • Your script should:
        • Delete all unnecessary archives (all archives minus the number to keep) in the versions folder
        • Delete all unnecessary archives (all archives minus the number to keep) in the /data/web_static/releases folder of both of your web servers
      • All remote commands must be executed on both of your web servers (using the env.hosts = ['<IP web-01>', 'IP web-02'] variable in your script)

      In the following example, the SSH key and the username used for accessing to the server are passed in the command line. Of course, you could define them as Fabric environment variables (ex: env.user =...)