python on rails - victory levy

49
Vic Levy Princeton Consultants, Inc. 590 5 th Ave, Floor 16 New York, NY [email protected] Python on Rails Advancing Safety with Locomotive-Hosted “Mobile” App NYC Python Meetup, April 17, 2014 Two Sigma Investments, LLC, New York, NY 1

Upload: hakka-labs

Post on 10-May-2015

2.725 views

Category:

Software


2 download

DESCRIPTION

http://www.hakkalabs.co/articles/python-rails

TRANSCRIPT

Page 1: Python on Rails - Victory Levy

Vic LevyPrinceton Consultants, Inc.590 5th Ave, Floor 16New York, [email protected]

Python on RailsAdvancing Safety with Locomotive-Hosted “Mobile” App

NYC Python Meetup, April 17, 2014Two Sigma Investments, LLC, New York, NY

1

Page 2: Python on Rails - Victory Levy

2Outline

Positive Train Control 101

COSMA: Agent on the locomotive

Programming COSMA

Testing

Page 3: Python on Rails - Victory Levy

3

Positive Train Control 101

Page 4: Python on Rails - Victory Levy

4

PTC is a federal law applying to Amtrak and Class-I railroads.

CSX is a Class-I railroad.

Page 5: Python on Rails - Victory Levy

5

• Chatsworth, CA, Sept 2008. Commuter and freight trains collide, many casualties

• Federal law passed same month• Class-1 railroads due Dec 2015

Page 6: Python on Rails - Victory Levy

6Warns crew when any of several classes of danger detected

Page 7: Python on Rails - Victory Levy

7If crew does not react to warning in time, PTC applies brakes

Page 8: Python on Rails - Victory Levy

8Impact of PTC on Class-I Railroads, Including CSX

• New back-office servers• New wayside devices• New communications systems

Page 9: Python on Rails - Victory Levy

9Impact of PTC on Class-I Railroads, Including CSX, Cont’d• New equipment on board locomotives

Page 10: Python on Rails - Victory Levy

10

New PTC Equipment Aboard CSX Locomotives: PTC Computer

Page 11: Python on Rails - Victory Levy

11

New PTC Equipment Aboard CSX Locomotives: Computer Displays

Page 12: Python on Rails - Victory Levy

12New PTC Equipment Aboard CSX Locomotives: 220-MHz Radio

Page 13: Python on Rails - Victory Levy

13

New PTC Equipment Aboard CSX Locomotives: Onboard Routing ServerCOSMA host system

Page 14: Python on Rails - Victory Levy

14New PTC Equipment Aboard CSX Locomotives

NEED: Checkout, monitor, upgrade these devices and more

Page 15: Python on Rails - Victory Levy

COSMA: Agent on the Locomotive

15

Page 16: Python on Rails - Victory Levy

16COSMA: CSX Onboard Systems Management Agent

Python

Page 17: Python on Rails - Victory Levy

17COSMA Primary Functions

1. Check out PTC equipment before deployment in the field

Page 18: Python on Rails - Victory Levy

18

COSMA Primary Functions, Cont’d2. Report on conditions, problems,

assets in the onboard PTC environment

3. Correct problems, either autonomously or on command

Page 19: Python on Rails - Victory Levy

19

COSMA Primary Functions, Cont’d4. Report on cell, radio and Wifi

signal strength

Page 20: Python on Rails - Victory Levy

20COSMA Primary Functions, Cont’d

5. Perform software updates to onboard systems, either in the shop or on the rail

Page 21: Python on Rails - Victory Levy

21

Programming COSMA

Page 22: Python on Rails - Victory Levy

22Realities of Programming in the Locomotive Environment

1. ?

Page 23: Python on Rails - Victory Levy

23Realities of Programming in the Locomotive Environment

1. No interfering with proper functioning of safety-critical systems

2. In and out of connectivity3. No controlled shutdown (circuit breaker)4. Cell bandwidth is expensive5. Limited writing to persistent storage

(SSD)

Page 24: Python on Rails - Victory Levy

24Realities of Programming in the Locomotive Environment, Cont’d

6. Stay aware of changes in the onboard environment

• Did we wake up on another locomotive?

• Are we in home territory?• What is the PTC state?

Page 25: Python on Rails - Victory Levy

25Realities of Programming in the Locomotive Environment, Cont’d

7. Python 2.6.68. Red Hat Enterprise Linux Server 6.2

Page 26: Python on Rails - Victory Levy

26COSMA Is Multi-Threaded

• Most thread asleep most of the time• Wake up, check something, go back to sleep

• Signal-mapping watches GPS for distance

Page 27: Python on Rails - Victory Levy

27Two Configuration Files:

Default (installed) Override (runtime)

Page 28: Python on Rails - Victory Levy

28

Two Configuration Files (ConfigParser Library)

Page 29: Python on Rails - Victory Levy

29

Pattern: JIT Configuration QueriesApplication is remotely configurable, so no caching configs in __init__

Page 30: Python on Rails - Victory Levy

30

Pattern: Subsystem QueryDon’t overtax onboard systems if recently sampled data is good enough

Page 31: Python on Rails - Victory Levy

31

Pattern: Logical Device

• Adapter pattern presents a common interface to business code querying devices with differing access methods

Page 32: Python on Rails - Victory Levy

32Pattern: No Self-Deprecating or Humorous Comments

Page 33: Python on Rails - Victory Levy

33Hardware Access Method: UDP

Nonintrusive read, no impact on monitored device

Monitored device must be broadcasting

Sample rate determined by device

Page 34: Python on Rails - Victory Levy

34

Hardware Access Method: UDP• How to create a UDP socket depends on whether sending or receiving, or receiving a broadcast

Page 35: Python on Rails - Victory Levy

35Hardware Access Method: SNMP• Available library: netsnmp

• Faster• Malformed OID can crash Python

• Available library: pysnmp• Pure-Python implementation• Slower• Unresponsive OID returns “NO DATA”

Page 36: Python on Rails - Victory Levy

36

Hardware Access Method: SNMPExample pt 1: Create netsnmp session

Page 37: Python on Rails - Victory Levy

37

Hardware Access Method: SNMPExample pt 2: Create a list of bindings

Page 38: Python on Rails - Victory Levy

38

Hardware Access Method: SNMPExample pt 3: Query and recombine

Page 39: Python on Rails - Victory Levy

39Hardware Access Method: SmartCtl

[vlevy@CSX-PTC3EAP-111100016 ~]$ sudo smartctl -a /dev/sda[sudo] password for vlevy:smartctl 5.39.1 2010-01-28 r3054 [i386-redhat-linux-gnu] (local build)Copyright (C) 2002-10 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===Device Model: FiD 2.5 SATA10000Serial Number: 20111005AAB000000030Firmware Version: 090928User Capacity: 7,998,455,808 bytesDevice is: Not in smartctl database [for details use: -P showall]ATA Version is: 7ATA Standard is: Exact ATA specification draft version not indicatedLocal Time is: Mon Apr 14 15:11:12 2014 EDTSMART support is: Available - device has SMART capability.SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===SMART overall-health self-assessment test result: PASSED

General SMART Values:Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled.Total time to complete Offlinedata collection: ( 0) seconds.Offline data collectioncapabilities: (0x00) Offline data collection not supported.SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer.Error logging capability: (0x00) Error logging NOT supported. No General Purpose Logging support.

SMART Attributes Data Structure revision number: 1280Vendor Specific SMART Attributes with Thresholds:ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 331 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 0194 Temperature_Celsius 0x0007 032 100 000 Pre-fail Always - 0229 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 259865206445036232 Available_Reservd_Space 0x0002 100 048 000 Old_age Always - 9037453799481233 Media_Wearout_Indicator 0x0002 100 000 000 Old_age Always - 0234 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 678655194114235 Unknown_Attribute 0x0002 100 000 000 Old_age Always - 4261534239

Warning: device does not support Error LoggingSMART Error Log Version: 16No Errors Logged

Warning: device does not support Self Test LoggingSMART Self-test log structure revision number 16Warning: ATA Specification requires self-test log structure revision number = 1No self-tests have been logged. [To run self-tests, use: smartctl -t]

Device does not support Selective Self Tests/Logging

SSD Statistics:• Power cycle

count• Erase cycle

percent• Average & max

erase count

Technique:• Parse to int• struct pack &

unpack

Page 40: Python on Rails - Victory Levy

40Hardware Access Method: Drive Vendor and Model

Page 41: Python on Rails - Victory Levy

41More Hardware Access Methods

• SSH• Telnet

Page 42: Python on Rails - Victory Levy

42

Development & Testing Environments

Page 43: Python on Rails - Victory Levy

43

Development: Eclipse & Pydev

Page 44: Python on Rails - Victory Levy

44

Unit Testing: unittest LibraryEclipse & Pydev rock. Also nosetests.

Page 45: Python on Rails - Victory Levy

45Testing Platforms: Lab

Page 46: Python on Rails - Victory Levy

46Testing Platforms: High-Rail

Page 47: Python on Rails - Victory Levy

47Testing Platforms: The Real Thing

Page 48: Python on Rails - Victory Levy

Vic [email protected]

Princeton Consultants, Inc.590 5th Ave, Floor 16New York, NY

Happy Springtime! 1

Page 49: Python on Rails - Victory Levy

Princeton Consultants, Inc.

• Blend of information-technology and management consulting

• Service offerings are business strategy, software development, process engineering and project management

• Clients include many of the best-known and most innovative companies

• 85 full-time, on-shore professionals work out of our offices in Princeton, N.J. and Midtown Manhattan

• Over 1,500 projects successfully delivered since our founding in 1980

• Corporate website: www.princeton.com

• Careers website: www.princeton.com/join

2 Research WayPrinceton, NJ 08540

590 Fifth AvenueNew York, NY 10036